#include #define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++) #define REP(i,n) FOR(i,0,n) #define MOD 1000000007 #define int long long using namespace std; typedef long long ll; typedef vector> mat; const int INF = 1e9; signed main() { int N; int X, Y; cin >> N; cin >> X >> Y; int ans = Y - X; if (ans <= 0) { cout << -1 << endl; return 0; } REP(i,N-1) { cin >> X >> Y; if (ans != Y - X) { cout << -1 << endl; return 0; } ans = Y - X; if (ans <= 0) { cout << -1 << endl; return 0; } } cout << ans << endl; }