#include "bits/stdc++.h" using namespace std; int main() { int N; cin >> N; int lmax = 0; int lmin = 99999999; for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; int len = a + b * 4; if (i != 0){ if (lmax % 2 != len % 2){ cout << -1 << endl; return 0; } } lmax = max(len, lmax); lmin = min(len, lmin); } cout << (lmax - lmin) / 2 << endl; }