N = int(input()) xy = [map(int, input().split()) for i in range(N)] x, y = [list(i) for i in zip(*xy)] res = -1 for i in range(N): square = y[i] - x[i] if i == 0: sq_ = square pass else: if square != sq_: res = -1 break else: res = square print(res)