#include"bits/stdc++.h" using namespace std; int main() { int N; cin >> N; vector X(N),Y(N); for (int i = 0; i < N; i++) cin >> X[i] >> Y[i]; bool flag=true; int sq; for (int i = 0; i < N; i++) { if(i==0) sq = Y[i]-X[i]; if (sq <= 0) { flag=false; break; } else { if (sq != (Y[i] - X[i])) { flag=false; break; } } } cout << (flag?sq:-1) << endl; }