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