import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) m = map(int,read().split()) AB = zip(m,m) diff = [b-a for a,b in AB] if len(set(diff)) > 1: print(-1) else: x = diff[0] if x <= 0: print(-1) else: print(x)