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

namespace Zad3
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string prvi = Console.ReadLine();
            string[] pom1= prvi.Split(' ');
            string drugi = Console.ReadLine();
            string[] pom2 = drugi.Split(' ');
            for(int i=0;i<n-2;i++)
            {
                string x = Console.ReadLine();
            }
            if(n==2)
            {
                if (pom1[0] == pom2[0] || pom1[1] == pom2[1])
                    Console.WriteLine("1");
                else
                    Console.WriteLine("0");
            }
            else
            {
                Console.WriteLine("0");
            }
        }
    }
}