#include using namespace std; int main() { int n, i, t; cin >> n; int a[n], b[n]; for (i = 0; i < n; i++) { cin >> a[i] >> b[i]; if (i == 0) {t = b[0] - a[0];} else { if (b[i] - a[i] != t) {t = -1; break;} } } if (t < 1) {t = -1;} cout << t << endl; return 0; }