#coding: utf-8 ##yuki_185 import sys s=[] n=int(raw_input()) for i in xrange(n): s.append(raw_input()) l=[] for i in range(0,len(s)): ltt=map(int,s[i].split()) lt=ltt[:2] l.append(lt) print l res=l[0][1]-l[0][0] if res<0: print -1 sys.exit() for i in xrange(1,len(l)): if len(l[i])==1: break if l[i][1]-l[i][0]<0 or l[i][1]-l[i][0] != res: print -1 sys.exit() print res