#include using namespace std; int a[1000]; int main() { int n; cin >> n; int ma = 0; for (int i = 0; i < n; ++i) { int b, c; cin >> b >> c; a[i] = b + 4 * c; ma = max(ma, a[i]); } int ans = 0; for (int i = 0; i < n; ++i) { if ((ma - a[i]) & 1) { cout << -1 << endl; return 0; } ans += (ma - a[i]) / 2; } cout << ans << endl; }