#include using namespace std; int main() { int n, d, t, x, y; bool f = true; cin >> n; cin >> x >> y; d = y - x; if (d <= 0) f = false; for (int i = 1; i < n; i++) { cin >> x >> y; if (!f) continue; t = y - x; if (t <= 0 || d != t) f = false; } cout << (f ? d : -1) << endl; return 0; }