#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; long long MOD = 1000000007; int main() { int N; cin >> N; int a; for ( int i = 0; i < N; i++ ) { int x,y; cin >> x >> y; if ( y-x <= 0 ) { a = -1; continue; } if ( a == -1 ) { continue; } if ( i && a != y-x ) { a = -1; continue; } a = y-x; } cout << a << endl; return 0; }