n=int(input()) t=[eval('-'+input().replace(' ','+')) for _ in range(n)] l=list(set(t)) if len(l)==1 and l[0]>0: print(l[0]) else: print(-1)