using System;

namespace _4zad
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("unesi n");
            int n = int.Parse(Console.ReadLine());
            int[,] a = new int[n, n];
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    a[i, j] = 0;
                }
            }
            for (int l = 0; l < n; l++)
            {
                string s = Console.ReadLine();
                int p = s.IndexOf(' ');
                int q = int.Parse(s.Substring(0, p))-1;
                int r = int.Parse(s.Substring(p+1))-1;
                a[r,q] = 1;
            }
            short br = 0;
            if(n==2)
            {
                short x1 = 0; short y1 = 0; short v1 = 0; short x2 = 0; short y2 = 0; short v2 = 0;
                for (short i = 0; i < n; i++)
                {
                    for (short j = 0; j < n; j++)
                    {
                        if (a[i,j] == 1)
                        {
                            if (v1==0)
                            {
                              y1 = i; x1 = j; v1 = 1;
                            }
                            else
                            {
                                x2 = j; y2 = i; v2 = 1;
                            }
                            
                        }

                    }
                }
                if (a[x1,y1] != 1)

                {
                    a[y2, x2] = 0;
                    a[x1, y1] = 1;
                    br++;
                }

            }
            Console.WriteLine(br);
            }
        }
    }