#include using namespace std; #define LL long long #define REP(i,n) for(int i=0; i<(n); i++) struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star; int main() { LL N; cin >> N; LL X, Y; set st; REP( i, N ){ cin >> X >> Y; st.insert( Y - X ); } auto it = st.begin(); cout << ( (LL)st.size() == 1 && *it > 0 ? *it : -1 ) << endl; return 0; }