#include using namespace std; typedef unsigned long long ul; typedef signed long long ll; int main(void) { cin.tie(0); ios::sync_with_stdio(false); cout << fixed; int n; cin >> n; ll x, y; cin >> x >> y; ll ans = y-x; if (ans <= 0) {cout << -1 << endl; return 0;} for (int i = 1; i < n; ++i) { cin >> x >> y; if (ans != y-x) {cout << -1 << endl; return 0;} } cout << ans << endl; return 0; }