N = int(input()) terms = [[int(x) for x in input().split()] for y in range(N)] forecast = None is_censored = True for term in terms: base,add = term if base >= add: break fc = add - base if not forecast: forecast = fc elif forecast != fc: break else: is_censored = False if is_censored: forecast = -1 print(forecast)