N = int(input().strip()) a = -1 for i in range(N): X, Y = (int(j) for j in input().strip().split(' ')) if a < 0: a = Y - X if a < 0: print('-1') exit(1) else: if a != Y - X: print('-1') exit(1) else: print(a)