#include <bits/stdc++.h>
#define ll long long
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
using namespace std;
mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
typedef vector<int> vi;
typedef vector<pii> vii;
typedef pair<int, pair<int, int>> iii;
typedef vector<unsigned int> vui;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vi vm;
typedef vector<vm> Mat;
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#else
// freopen("outofplace.in", "r", stdin);
// freopen("outofplace.out", "w", stdout);
#endif
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;
int n, k, m; cin >> n >> k >> m;
int cnt = 0;
ll sum = 0;
for (int i = 0; i < n; ++i) {
int x, y; cin >> x >> y;
sum += x;
if ((x & 1) != (y & 1)) ++cnt;
}
if (cnt != n && cnt != 0) {
if (k & 1) {
cout << 1 << '\n';
} else {
cout << 2 << '\n';
}
} else {
if (cnt == 0) {
if ((sum & 1) == m) {
cout << 1 << '\n';
} else {
cout << 2 << '\n';
}
} else {
if (abs((sum & 1) - m) == (k & 1)) {
cout << 1 << '\n';
} else {
cout << 0 << '\n';
}
}
}
return 0;
}
Copy