#include <bits/stdc++.h>
using namespace std;
void out (int x) {
cout << x;
exit(0);
}
int main (){
#ifndef ONLINE_JUDGE
freopen("SuhaibSawalha1","r",stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k, p;
cin >> n >> k >> p;
k &= 1;
long long s = 0;
array<int, 2> a[n];
bool keep = 0, change = 0;
for (int i = 0; i < n; ++i) {
cin >> a[i][0] >> a[i][1];
s += a[i][0];
keep |= a[i][0] == a[i][1];
change |= a[i][0] != a[i][1];
}
if ((s & 1) == p) {
out(keep ? 1 : 2);
}
if (change) {
out(k ? 1 : 2);
}
out(2);
return 0;
}
Copy