#include #define FOR(i,a,b) for(int i = (a); i < (b); ++i) #define REP(i,n) FOR(i,0,n) #define SZ(n) (int)(n).size() using namespace std; typedef long long ll; typedef vector VI; int main() { int n; cin >> n; int x, y; cin >> x >> y; int ans = y - x; FOR(i, 1, n) { int x, y; cin >> x >> y; if (ans != y - x) { cout << "-1" << endl; return 0; } } if(ans >= 0) cout << "-1" << endl; else cout << ans << endl; return 0; }