#include using namespace std; int main() { int n; cin >> n; int x, y; cin >> x >> y; int t = y - x; if (t <= 0) t = -1; for (int i = 0; i < n - 1; i++) { int x2, y2; cin >> x2 >> y2; if (t + x2 != y2) t = -1; } cout << t << '\n'; return 0; }