#include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(i,s,e) for (int i = int(s); i < int(e); i++) #define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) #define ISEQ(c) (c).begin(), (c).end() int SURP = 1000000007; int main(){ int N; cin >> N; int width[N]; int maxw = 0; FOR(i,0,N){ int ai,bi; cin >> ai >> bi; width[i] = ai + 4 * bi; if(maxw < width[i]) maxw = width[i]; } int cnt = 0; FOR(i,0,N){ int diff = maxw - width[i]; if (diff%2 != 0){ cnt = -1; break; }else{ cnt += diff/2; } } cout << cnt << endl; return 0; }