#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, c, d; if (N == 1) { cin >> a >> b; if (b <= a) { cout << -1 << endl; } else { cout << b - a << endl; } } else { cin >> a >> b; int ans1 = b - a; if (b <= a) { cout << -1 << endl; return 0; } cin >> c >> d; int ans2 = d - c; if (d <= c) { cout << -1 << endl; return 0; } if (ans1 == ans2) { cout << ans1 << endl; } else { cout << -1 << endl; } } return 0; }