#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define INF (1 << 30) #define INFLL (1LL << 60) int main() { long long int n,x,y; cin >> n; long long int ans; for(int i = 0;i < n;i++){ cin >> x >> y; if(i == 0) ans = y-x; if(y-x != ans) { ans = INFLL; break; } } if(ans <= 0) ans = INFLL; if(ans == INFLL) cout << "-1" << endl; else cout << ans << endl; return 0; }