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