#include using namespace std; int main(){ int n; cin >> n; vector c(n); for(int i = 0; i < n; i++){ int a , b; cin >> a >> b; c[i] = a + 4 * b; } sort(c.begin() , c.end()); int ans = 0; for(int i = 0; i < n - 1; i++){ int d = c[n - 1] - c[i]; if(d % 2 == 1){ cout << -1 << endl; exit(0); } ans += d / 2; } cout << ans << endl; return 0; }