#include using namespace std; int main() { int n; cin >> n; set st; bool flag = true; for (int i = 0; i < n; ++i) { int x, y; cin >> x >> y; if (y - x <= 0) { flag = false; } else { st.insert(y - x); } } if (flag and st.size() == 1) { cout << *st.begin() << endl; } else { cout << -1 << endl; } return 0; }