#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vector X(N), Y(N); for (int i = 0; i < N; i++) { cin >> X[i] >> Y[i]; } int res = Y[0] - X[0]; for (int i = 0; i < N; i++) { if (res != Y[i] - X[i]) { cout << -1 << '\n'; return 0; } } cout << (res < 0 ? -1 : res) << '\n'; return 0; }