#coding: utf-8 ##yuki_185 import sys n=int(raw_input()) for i in xrange(n): s=map(int,raw_input().split()) x=s[0] y=s[1] if i==0: if y-x>0: temp=y-x else: print -1 sys.exit() else: if y-x>0 and temp==y-x: continue else: print -1 sys.exit() res=temp print res