#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    if(n==1){
        int red1,kolona1;
        cin>>red1>>kolona1;
        cout<<0<<endl;
    }
    if(n==2){
        int red1,kolona1,red2,kolona2;
        cin>>red1>>kolona1>>red2>>kolona2;

        if(red1==1 and kolona1==1 and red2==2 and kolona2==2)cout<<0<<endl;
        else if(red1==1 and kolona1==2 and red2==2 and kolona2==1)cout<<0<<endl;
        else if(red1==2 and kolona1==1 and red2==1 and kolona2==2)cout<<0<<endl;
        else if(red1==2 and kolona1==2 and red2==1 and kolona2==1)cout<<0<<endl;
        else cout<<1<<endl;
    }
return 0;
}