#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int bp=0;
    int A[n];
    int B[n];
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        A[i]=a;
        B[i]=b;
    }
    int p=0,f=1;
    for(int i=0;i<=n;i++){
        p+=i;
        f++;
    }
    int a=0;
    for(int i=0;i<n;i++){
        a+=A[i];
    }
    int b=0;
    for(int i=0;i<n;i++){
        b+=B[i];
    }
    int ar=abs(a-p);
    int br=abs(b-p);
    if((ar==0)&&(A[0] == B[1])){
        ar=n-1;;
    }
    if((br==0)&&(B[0] == B[1])){
        br=n-1;
    }
    bp=ar+br;
    cout<<bp<<endl;
}