while True:
try:
string1=input()
string2=input()
string3=input()
Netmask = string1.split(".")
Ip1 = string2.split(".")
Ip2 = string3.split(".")
ans=-1
for i in range(4):
while i<4:
if i == 3 :
break
elif (int(Netmask[i])<255 and int(Netmask[i+1]) != 0) or int(Netmask[i])>255 or int(Netmask[i])<0 :
ans = 1
break
else:
break
while int(Ip1[i]) < 0 or int(Ip1[i]) >=255 or int(Ip2[i]) <0 or int(Ip2[i]) >=255:
ans = 1
break
if ans == -1 or ans == 0:
mask = int(Netmask[i])
ip1 = int(Ip1[i])
ip2 = int(Ip2[i])
#print(mask)
Ip1[i] = mask and ip1
Ip2[i] = mask and ip2
if Ip1[i] == Ip2[i]:
ans = 0
else:
ans = 2
print(ans)
except:
break