#include #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int n; cin >> n; int ans; rep(i, n) { int x, y; cin >> x >> y; int z = y - x; ans = (z > 0 && (i == 0 || ans == z)) ? z : -1; } cout << ans << endl; }