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