#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; imp = !(0 <= diff); for (int i = 2; i <= n; i++) { scanf("%d %d", &x, &y); if (y - x != diff) imp = 1; } if (imp) printf("-1\n"); else printf("%d\n", diff); }