import sys
# 判断掩码合法性
def valadd(add):
    res=''
    for d in add:
        if d<0 or d>255:
            return 0
        else:
            #10转2
            b = f"{d:08b}"
            res+=b
    if '01' in res:
        return 0
    if '0' not in res or '1' not in res:
        return 0
    return 1
# 判断ip合法性
def valip(ip):
    for d in ip:
        if d<0 or d>255:
            return 0
    return 1
# 数字转32位二进制再转十进制
def solveda(da):
    res=''
    for d in da:
        #10转2
        b = f"{d:08b}"
        res+=b
    r = int(res,2)
    return r

while 1:
    try:
        add = list(map(int,input().split('.')))
        ip1 = list(map(int,input().split('.')))
        ip2 = list(map(int,input().split('.')))

        if valadd(add) and valip(ip1) and valip(ip2):
            if solveda(add) & solveda(ip1) == solveda(add) & solveda(ip2):
                print("0")
            else:
                print("2")
        else:
            print("1")
    except:
        break