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