n = int(input()) res = [] for _ in range(n): x,y = map(int,input().split()) res.append(y-x) if n*[res[0]]==res and res[0]>0: print(res[0]) else: print(-1)