n = int(input()) r = [0]*n for i in range(n): a,b = map(int,input().split()) r[i] = b-a print(r[0] if r[0] > 0 and all(r[0]==ri for ri in r) else -1)