# -*- coding: utf-8 -*- n = int(input()) x = [0] * n y = [0] * n for i in range(n): temp = list(map(int,input().split())) x[i] = temp[0] y[i] = temp[1] ans = y[0] - x[0] if ans > 0: for i in range(n): if y[i] - x[i] != ans: print("-1") break else: print(ans) else: print("-1")