#include <algorithm>
#include <iostream>
#include <vector>

int main()
{
    unsigned long long N;
    std::cin >> N;

    std::vector<unsigned long long> rows(N, 0);
    std::vector<unsigned long long> columns(N, 0);

    for (unsigned long long i = 0; i < N; i++)
    {
        unsigned long long x, y;
        std::cin >> x >> y;

        rows[--x]++;
        columns[--y]++;
    }

    unsigned long long moves = 0;

    auto notone = std::find_if_not(rows.begin(), rows.end(), [](unsigned long long i) { return i <= 1; });
    while (notone != rows.end())
    {
        (*notone)--;
        (*(std::find_if(rows.begin(), rows.end(), [](unsigned long long i) { return i == 0; })))++;
        notone = std::find_if_not(rows.begin(), rows.end(), [](unsigned long long i) { return i <= 1; });
        moves++;
    }

    notone = std::find_if_not(columns.begin(), columns.end(), [](unsigned long long i) { return i <= 1; });
    while (notone != columns.end())
    {
        (*notone)--;
        (*(std::find_if(columns.begin(), columns.end(), [](unsigned long long i) { return i == 0; })))++;
        notone = std::find_if_not(columns.begin(), columns.end(), [](unsigned long long i) { return i <= 1; });
        moves++;
    }

    std::cout << moves;

    return 0;
}