#include using namespace std; int main() { int n; cin >> n; int x1, y1; cin >> x1 >> y1; int ans = y1 - x1; bool is_valid = ans > 0? true: false; for (int i = 0; i < n - 1; ++i) { int x, y; cin >> x >> y; if (y - x != ans) is_valid = false; } if (!is_valid) puts("-1"); else cout << ans << '\n'; return 0; }