#include #define rep(i,a,n) for (int i = a;i < n;i++) #define per(i,n,a) for (int i = n-1;i >= a;i--) using namespace std; int main() { int n; cin >> n; int x[n], y[n], c = -1; rep(i, 0, n) { cin >> x[i] >> y[i]; if (c == -1) c = y[i] - x[i]; else if (c != y[i] - x[i]) { cout << -1 << endl; return 0; } if (c <= 0) { cout << -1 << endl; return 0; } } cout << c << endl; }