import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main{
public static void main(String[] args) throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String[] mask = bf.readLine().split("\\.");
String[] ip1 = bf.readLine().split("\\.");
String[] ip2 = bf.readLine().split("\\.");
long a=0,b=0,c=0;
for(int i=0;i<4;i++) {
int m1 = Integer.parseInt(mask[i]);
int m2 = Integer.parseInt(ip1[i]);
int m3 = Integer.parseInt(ip2[i]);
if((m1<0||m1>>8>0)||(m2<0||m2>>8>0)||(m3<0||m3>>8>0)){
System.out.println(1);
return;
}
a = a<<8|m1;
b = b<<8|m2;
c = c<<8|m3;
}
if((((a^0XFFFFFFFFL)+1)|a)!=a){
System.out.println(1);
return;
}
long r1=a&b,r2=a&c;
System.out.println(r1==r2?0:2);
}
}