#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;

    vector<pair<int, int>> v;
    int a, b;
    int mat[1000][1000] = {};
    for (int i = 0; i < n; i++){
        cin >> a >> b;
        v.push_back({a, b});
        mat[a][b] = 1;
    }

    if (n == 2){
        if (mat[0][0] == mat[0][1] || mat[0][0] == mat[1][0] || mat[0][1] == mat[1][1])
            cout << 1 << endl;
        else
            cout << 0 << endl;
    }else{
        cout << 0 << endl;
    }

    return 0;
}