c=-1 for _ in[0]*int(input()): a,b=map(int,input().split()) if a>b or a==b:print('-1');exit() if c==-1:c=b-a elif c!=b-a:print('-1');exit() print(c)