#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int n, r, c;
    int i, z, zr=0, zc=0, rr, rc;
    scanf("%d", &n);
    z = (n * (n + 1)) / 2;
    for(i=0;i<n;i++)
    {
        scanf("%d%d", &r, &c);
        zr += r;
        zc += c;
    }
    if(zr == z && zc == z)
    {
        printf("0");
    }
    rr = abs(z - zr);
    rc = abs(z - zc);
    if(rr < rc)
    {
        printf("%d", rr);
    }
    else if(rr == rc)
    {
        printf("%d", rr+1);
    }
    else
    {
        printf("%d", rc);
    }
    return 0;
}