#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define INF (INT_MAX/3) #define PI (2*acos(0.0)) #define EPS (1e-8) typedef long long ll; typedef unsigned long long ull; int main(){ ios_base::sync_with_stdio(0); int N, a, b, m; cin >> N; vector L(N); for(int i = 0; i < N; i++){ cin >> a >> b; L[i] = a + b * 4; m = max(L[i], m); } ll ans = 0; for(int i = 0; i < N; i++){ ans += m - L[i]; } if(ans & 1) cout << -1 << endl; else cout << ans / 2 << endl; return 0; }