#include #include #include #include #include #include using namespace std; using ll = long long; int main() { int N; cin >> N; set s; for(int i=0; i> x >> y; s.insert(y-x); } if(s.size() != 1 || *s.begin() <= 0) { cout << -1 << endl; } else { cout << *s.begin() << endl; } }