import numpy as np n = int(input()) xy = np.array([list(map(int, input().split())) for _ in range(n)], np.int64) z = xy[:, 1] - xy[:, 0] if (z == z[0]).all(): print(z[0]) else: print(-1)