#include <stdio.h>
#include <string.h>

int main()
{
  //get str;
  int mask[4];
  int ip1[4], ip2[4];
  while (scanf("%d.%d.%d.%d", mask, mask + 1, mask + 2, mask + 3) != EOF)
  {
    scanf("%d.%d.%d.%d", ip1, ip1 + 1, ip1 + 2, ip1 + 3);
    scanf("%d.%d.%d.%d", ip2, ip2 + 1, ip2 + 2, ip2 + 3);
    //判断合法
    int islegal = 1;
    for (int i = 0; i < 4; i++)
    {
      if (mask[i] < 0 || mask[i] > 255 || ip1[i] < 0 || ip1[i] > 255 || ip2[i] < 0 || ip2[i] > 255)
      {
        islegal = 0;
        break;
      }
    }
    //转换成无符号32位
    unsigned int mask_num, ip1_num, ip2_num;
    mask_num = (mask[0] << 24) + (mask[1] << 16) + (mask[2] << 8) + mask[3];
    //判断mask是否合法
    mask_num = ~mask_num;
    if ((mask_num + 1 & mask_num) !=0)
      islegal = 0;

    if (islegal == 0)
    {
      printf("1\n");
    }
    else if (islegal == 1)
    {
      mask_num = ~mask_num;
      ip1_num = (ip1[0] << 24) + (ip1[1] << 16) + (ip1[2] << 8) + ip1[3];
      ip2_num = (ip2[0] << 24) + (ip2[1] << 16) + (ip2[2] << 8) + ip2[3];

      if ((mask_num & ip1_num) == (mask_num & ip2_num))
        printf("0\n");

      else
        printf("2\n");
    }
  }

  return 0;
}