#include #define rep(i, ss, ee) for (int i = ss; i < ee; ++i) using namespace std; int solve() { int N, a, b, c; cin >> N; vector v(N); rep(i, 0, N) { cin >> a >> b; v[i] = b - a; if (v[i] < 0) return -1; } if (N == 1) return v[0]; rep(i, 0, N - 1) if (v[i] != v[i + 1]) return -1; return v[0]; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << solve() << endl; getchar(); }