import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextLine()) { // 注意 while 处理多个 case
String str = in.nextLine();
String Ip1 = in.nextLine();
String Ip2 = in.nextLine();
boolean ishefa = isIp(Ip1) && isIp(Ip2) && isYanMA(str);
if (!ishefa) {
System.out.println(1);
} else {
System.out.println(isSupper(str, Ip1, Ip2) ? 0 : 2);
}
}
}
public static boolean isSupper(String str, String ip1, String ip2) {
String[] strArray = str.split("\\.");
String[] ip1Array = ip1.split("\\.");
String[] ip2Array = ip2.split("\\.");
for (int i = 0; i < 4; i++) {
int str11 = Integer.parseInt(strArray[i]);
int ip11 = Integer.parseInt(ip1Array[i]);
int ip12 = Integer.parseInt(ip2Array[i]);
if ((str11 & ip11) != (str11 & ip12)) return false;
}
return true;
}
public static boolean isIp(String ip) {
String[] ipArray = ip.split("\\.");
for (String tt : ipArray) {
int temp = Integer.parseInt(tt);
if (temp < 0 || temp > 255) return false;
}
return true;
}
public static boolean isYanMA(String str) {
int index = str.indexOf('0');
if (index == -1) return true;
String str0 = str.substring(index);
String strOne = str.substring(0, index);
String[] str00 = str0.split("\\.");
for (String tt : str00) {
if (Integer.parseInt(tt) != 0) return false;
}
String[] str111 = strOne.split("\\.");
for (int i = 0; i < str111.length - 1; i++) {
if (Integer.parseInt(str111[i]) != 255) return false;
}
int temp = Integer.parseInt(str111[str111.length - 1]);
if (temp < 0 || temp > 255) return false;
String number = Integer.toString(temp, 2);
int index0 = number.indexOf('0');
if (index0 == -1) return true;
for (int i = 0; i < index0; i++) {
if (number.charAt(i) == '0') return false;
}
for (int j = index0; j < number.length() - 1; j++) {
if (number.charAt(j) == '1') return false;
}
return true;
}
}