#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define mp make_pair #define pb push_back #define REP(i,a,n) for(int i = a;i < (n);i++) #define rep(i,n) for(int i = 0;i < (n);i++) #define all(s) s.begin(), s.end() #define rall(s) s.rbegin(), s.rend() #define range(x,min,max) ((min) <= (x) && (x) <= (max)) using namespace std; typedef long long LL; typedef vector VI; typedef vector > VII; typedef pair PII; const int DX[]={1,0,-1,0},DY[]={0,-1,0,1}; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; int ans = 0; VI xs, ys; cin >> N; rep(i, N){ int x, y; cin >> x >> y; xs.pb(x); ys.pb(y); } rep(i, N){ if(ys[i] - xs[i] < 0 || (ans != 0 && ans != ys[i] - xs[i])){ ans = -1; break; } else { ans = ys[i] - xs[i]; } } cout << ans << endl; return 0; }