#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair i_i; typedef pair ll_i; typedef pair d_i; typedef pair ll_ll; typedef pair d_d; struct edge { int v, w; }; ll MOD = 1000000009; ll _MOD = 1000000009; double EPS = 1e-10; int main() { int N; cin >> N; vector x(N); bool even = false, odd = false; int maxi = 0; for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; x[i] = a + b * 4; if (x[i] % 2 == 0) even = true; else odd = false; maxi = max(maxi, x[i]); } if (even && odd) { cout << -1 << endl; return 0; } ll ans = 0; for (int i = 0; i < N; i++) ans += (maxi - x[i]) / 2; cout << ans << endl; }