using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n=Convert.ToInt32(Console.ReadLine());
            string[] fr = Console.ReadLine().Split();
            if (n == 1)
            {
                Console.WriteLine("0");
            }
            else
            {
                string[] sc = Console.ReadLine().Split();
                if (fr[0] == sc[0] || fr[1] == sc[1])
                    Console.WriteLine("1");
                else
                    Console.WriteLine("0");
            }
        }
    }
}