#include #include #include #include using namespace std; int main(){ int n; cin >> n; vector a(n); vector b(n); for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; int ans,check; bool flag = true; for (int i = 0; i < n; i++) { ans = b[i] - a[i]; if (i != 0 && ans != check) { flag = false; break; } check = ans; } if (n == 1)flag = false; if (flag) cout << ans << endl; else cout << -1 << endl; return 0; }