#定义函数:将一个十进制数转化为八位二进制数
def fun1(x):
    res = [0]*8
    n = 0
    while x > 0:
        res[-1-n] = x % 2
        x = x // 2
        n = n + 1
    return res
while True:
    try:
        #获取三行输入数据
        data1 = input()
        data2 = input()
        data3 = input()
        
        #定义一个标签
        flag = 'False'
        #获得子网掩码的每一段
        x1 = data1.split('.')
        for word in x1:
            if int(word) > 255 or int(word) < 0:
                flag = 1

        #将子网掩码转化为二进制
        er1 = []
        for n in range(0,4):
            try:
                er1 += fun1(int(x1[n]))
            except:
                flag = 1
        #定义空数组存储所有的子网掩码
        zi = []
        res = [0]*32
        for n in range(0,32):
            for m in range(0,n):
                res[m] = 1
            if res != [0]*32:
                zi.append(res)
                res = [0]*32
        if er1 not in zi:
            flag = 1
        #获得IP地址的每一段
        x2 = data2.split('.')
        x3 = data3.split('.')
        
        for word in x2:
            if int(word) > 255 or int(word) < 0:
                flag = 1
        for word in x3:
            if int(word) > 255 or int(word) < 0:
                flag = 1
        if flag == 1:
            print(flag)
        else:
            er1 = []
            er2 = []
            er3 = []
            #将子网掩码和IP地址转化为二进制
            for n in range(0,4):
                er1 += fun1(int(x1[n]))
            for n in range(0,4):
                er2 += fun1(int(x2[n]))
            for n in range(0,4):
                er3 += fun1(int(x3[n]))
            #将子网掩码和IP地址进行与运算
            yu12 = ['Flase'] * 32
            yu13 = ['False'] * 32
            for n in range(0,32):
                if int(er1[n]) == 1 and int(er2[n]) == 1:
                    yu12[n] = 1
                else:
                    yu12[n] = 0
            for n in range(0,32):
                if int(er1[n]) == 1 and int(er3[n]) == 1:
                    yu13[n] = 1
                else:
                    yu13[n] = 0
            if yu12 == yu13:
                print(0)
            else:
                print(2)
            
        
        
        
    except:
        break