N = int(input()) a = [input().split() for i in range(N)] tmp = int(a[0][1]) - int(a[0][0]) for i in range(N): if int(a[i][1]) - int(a[i][0]) != tmp: print(-1) exit() tmp = int(a[i][1]) - int(a[i][0]) if tmp < 1: print("-1") exit() print(tmp)