#include using namespace std; int main(void) { int N, X, Y, ans; bool error = false; cin >> N; for(int i = 0; i < N; i++) { cin >> X >> Y; if(i == 0) ans = Y - X; if(Y - X != ans) { error = true; } else if(ans < 1) { error = true; } } if(error) { cout << "-1" << endl; } else { cout << ans << endl; } }