#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { int N, X[1005], Y[1005]; cin >> N; for (int i = 0; i < N; i++) { cin >> X[i] >> Y[i]; } int ans = 0; for (int i = 0; i < N; i++) { ans = Y[i] - X[i]; if (i > 0) { if (ans != Y[i] - X[i]) { cout << -1 << endl; return 0; } } } if (ans <= 0) cout << -1 << endl; else cout << ans << endl; return 0; }