#include //cin, cout #include //vector #include //sort,min,max,count #include //string,getline, to_string #include //abs(int) #include //swap, pair #include //deque #include //INT_MAX #include //bitset #include //sqrt, ceil. M_PI, pow, sin #include //fixed #include //setprecision using namespace std; int main() { int N; cin >> N; int a, b; if (N == 1) { cin >> a >> b; if (b <= a) { cout << -1 << endl; } else { cout << b - a << endl; } } else { cin >> a >> b; if (b <= a) { cout << -1 << endl; return 0; } int ans = b - a; for (int i = 1; i < N; i++) { cin >> a >> b; int temp = b - a; if (temp <= 0) { cout << -1 << endl; } if (ans != temp) { cout << -1 << endl; return 0; } } cout << ans << endl; } return 0; }