#include #include #include using namespace std; using ll = long long; //185 int main() { int n, x, y, diff, imp = 0; scanf("%d %d %d", &n, &x, &y); diff = y - x; for (int i = 2; i <= n; i++) { scanf("%d %d", &x, &y); if (diff + x != y) imp = 1; } if (imp) printf("-1\n"); else printf("%d\n", diff); }