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