a=int(input()) b=[] for i in range(a): b.append(input().split()) c=[] for i in range(2): c.append(int(b[i][1])-int(b[i][0])) if len(c)==c.count(c[0]): print(c[0]) else: print("-1")