#include <stdio.h>
#include <string.h>
#define SIZE 15
int ishefa(int *ym,int *ip1,int *ip2)
{
int flag=1;
for(int i=0;i<4;i++)
{
if(0<=ip1[i] && ip1[i]<=255)
;
else
flag=0;
if(0<=ip2[i] && ip2[i]<=255)
;
else
flag=0;
}
for(int i=0;i<3;i++)
{
if(ym[i]<ym[i+1])
flag=0;
}
if(flag==1)
return 1;
else
return 0;
}
int main(void)
{
char Yanma[SIZE]={'\0'};
char IP1[SIZE]={'\0'};
char IP2[SIZE]={'\0'};
while(scanf("%s\n",Yanma) !=EOF)
{
scanf("%s\n",IP1);
scanf("%s\n",IP2);
/*
printf("%s\n",Yanma);
printf("%s\n",IP1);
printf("%s\n",IP2);
*/
int ym[4]={0};
int ip1[4]={0};
int ip2[4]={0};
sscanf(Yanma,"%d.%d.%d.%d",ym,ym+1,ym+2,ym+3);
sscanf(IP1,"%d.%d.%d.%d",ip1,ip1+1,ip1+2,ip1+3);
sscanf(IP2,"%d.%d.%d.%d",ip2,ip2+1,ip2+2,ip2+3);
//is hefa
int hefa;
hefa=ishefa(ym,ip1,ip2);
//jishun
int sum1[4];
int sum2[4];
int flag=1;
for(int i=0;i<4;i++)
{
sum1[i]=ip1[i]&ym[i];
sum2[i]=ip2[i]&ym[i];
if(sum1[i]!=sum2[i])
flag=0;
}
if(hefa==0)
printf("1\n");
else
{
if(flag==1)
printf("0\n");
else
printf("2\n");
}
}
return 0;
}