#include using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector v(n); for(int i = 0; i < n; i++) { int a, b; cin >> a >> b; v[i] = a + b * 4; } sort(v.rbegin(), v.rend()); long long ans = 0; for(int i = 0; i < n; i++) { cerr << v[i] << endl; } for(int i = 1; i < n; i++) { if((v[0] - v[i]) % 2 == 0) { ans += (v[0] - v[i]) / 2; } else { cout << -1 << endl; return 0; } } cout << ans << endl; return 0; }