#coding:utf-8 n=input() a=[raw_input().split() for i in range(n)] s=set() for i in a: s.add(int(i[1])-int(i[0])) s_list=list(s) if len(s_list) == 1 and 0 <= s_list[0]: print s_list[0] else: print -1