//Normal #define _GLIBCXX_DEBUG #define ll long long #include using namespace std; using Graph = vector>; void print(auto a){ cout << a; } void prints(auto a){ cout << a << " "; } void prints(){ cout << " "; } void printl(auto a){ cout << a << endl; } void printl(){ cout << endl; } void fix(int n){ cout << fixed << setprecision(n); } int main(){ int N; cin >> N; vector> X(N, vector(2)); int maxv = 0; for(int i = 0; i < N; i++){ cin >> X[i][0] >> X[i][1]; maxv = max(maxv, X[i][0]+X[i][1]*4); } ll ans = 0; for(int i = 0; i < N; i++){ int diff = maxv - (X[i][0]+X[i][1]*4); if(diff%2 != 0){ printl(-1); return 0; } ans += diff/2; } printl(ans); return 0; }