N = input() L =[] for i in range(0,N): first = raw_input() split_first = first.split() X = int(split_first[0]) Y = int(split_first[1]) L.append(Y-X) L=set(L) if len(set(L)) == 1: L = list(L) if L[0] >= 1: print L[0] else: print -1 else: print -1