#include using namespace std; int main() { int N; set S; cin >> N; while (N--) { int x, y; cin >> x >> y; S.insert(y - x); } int ans = *S.begin(); if (ans <= 0 || S.size() != 1) ans = -1; cout << ans << endl; }