#include #define rep(i, n) for (int i = 0; i < (int)n; ++i) #define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i) #define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i) #define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++) #define all(v) v.begin(), v.end() #define mset(a, n) memset(a, n, sizeof(a)) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector vi; typedef vector vs; typedef vector > vvi; typedef vector > vpii; typedef pair pii; typedef pair pll; const int inf = 1000000000; const int mod = 1000000007; const double EPS = 1e-9; const int dx[] = { -1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1}; int N; int main() { // cin.tie(0); // tie // ios::sync_with_stdio(false); // sync cin >> N; int a[N], b[N]; int maxi = -1; rep(i, N) { cin >> a[i] >> b[i]; maxi = max(maxi, a[i] + 4 * b[i]); } int ans = 0; rep(i, N) { if ((maxi - (a[i] + 4 * b[i])) % 2 != 0) { ans = -1; break; } ans += (maxi - (a[i] + 4 * b[i])) / 2; } cout << ans << endl; return 0; }