#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { int n; cin >> n; vector> v(n); rep(i, n) cin >> v[i].first >> v[i].second; int maxim = 0; for (auto [a, b] : v) maxim = max(maxim, a + 4 * b); ll ans = 0; for (auto [a, b] : v) { int x = a + 4 * b; if (x % 2 != maxim % 2) { cout << -1 << endl; return 0; } ans += (maxim - x) / 2; } cout << ans << endl; return 0; }