N = int(input()) a, b = map(int, input().split()) c = b-a flg = 0 for i in range(N -1): a, b = map(int, input().split()) if c != b-a: flg = 1 break if flg == 1 or c < 0: print("-1") else: print(c)