#include using namespace std; int main() { // Input int N, X, Y; cin >> N >> X >> Y; // Output int Z = Y - X; if (Z <= 0) { cout << -1 << endl; return 0; } for (int i = 0; i < N - 1; ++i) { int XX, YY; cin >> XX >> YY; if (Z + XX != YY) { cout << -1 << endl; return 0; } } cout << Z << endl; }