#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(y[0] - x[0] <= 0) ans = -1; else ans = y[0] - x[0]; for(int i = 1;i < n;i++) if(y[i] - x[i] <= 0 || ans != y[i] - x[i]) ans = -1; cout << ans << endl; }