#include using namespace std; int main() { int N; cin >> N; long long X, Y,temp = -1; for (int i = 0; i < N;i++) { cin >> X >> Y; if (Y - X <= 0) { cout << -1 << endl; return 0; } if (temp == -1) { temp = Y - X; continue; } if (temp != Y - X) { cout << -1 << endl; return 0; } } cout << temp << endl; return 0; }