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