#include int main(void){ int i; int N, X, Y; int A[1000]; int flag = 0; scanf("%d", &N); for(i = 0; i < N; i++){ scanf("%d %d", &X, &Y); A[i] = Y - X; } for(i = 1; i < N; i++){ if(A[0] != A[i]){ flag = 1; break; } } if(flag == 1) printf("-1\n"); else if(A[0] < 0) printf("-1\n"); else printf("%d\n", A[0]); return 0; }