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

namespace zadatak_1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[,] a = new int[n, n];
            int w = 0;
            int f = 0;
            for (int i = 0; i < n; i++)
            {
                var ulazna_linija = Console.ReadLine().Split();
                int x = int.Parse(ulazna_linija[0]);
                int y = int.Parse(ulazna_linija[1]);
                a[x-1, y-1] = 1;

            }
            for (int i = 0; i < n; i++)
            {
                for (int k = 0; k < n; k++)
                {
                    if (a[i, k] != 1)
                    {
                        a[i, k] = 0;
                    }
                }
            }
            int c = 0;
            for (int i = 0; i < n; i++)
            {
                for (int k = 0; k < n; k++)
                {
                    if (a[i, k] != 1)
                    {
                        c = 0;
                        for (int l = 0; l < n; l++)
                        {
                            if (a[i, l] == 1)
                                c++;
                        }
                        for (int l = 0; l < n; l++)
                        {
                            if (a[l, k] == 1)
                                c++;
                        }
                        if (c == 1)
                            a[i, k] = 2;

                    }
                }
                
            }

            for (int i = 0; i < n; i++)
            {
                for (int k = 0; k < n; k++)
                {
                    if (a[i, k] == 1)
                    {
                        for (int l = 0; l < n; l++)
                        {
                            if (a[i, l] == 1 || a[l, k] == 1)
                            {
                                for (int m = 0; m < n; m++)
                                {
                                    for (int y = 0; y > n; y++)
                                    {

                                        if (a[m, y] == 2)
                                        {
                                            a[i, k] = 0;
                                            a[m, y] = a[i, k];
                                            w++;

                                        }
                                        if (w == 0)
                                        {
                                            f++;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            
            Console.WriteLine(w);


        }
    }
}