netmask = input() ip1 = input() ip2 = input() def valid(netmask, ip1, ip2): # 判断子网掩码是否合法 ss = "" int_mask = 0 for s in netmask.split("."): if len(s) == 0 or int(s) > 255 or int(s) < 0: return 1 int_mask = int_mask * 256 + int(s) ss = ss + "{:08b}".format(int(s)) if ss.find('0') - ss.rfind('1') != 1: return 1 # 判断ip1和ip2是否合法 int_ip1, int_ip2 = 0, 0 for s in ip1.split("."): if len(s) == 0 or int(s) > 255 or int(s) < 0: return 1 int_ip1 = int_ip1 * 256 + int(s) for s in ip2.split("."): if len(s) == 0 or int(s) > 255 or int(s) < 0: return 1 int_ip2 = int_ip2 * 256 + int(s) if int_ip1 & int_mask == int_ip2 & int_mask: return 0 else: return 2 print(valid(netmask, ip1, ip2))