n=gets.to_i a=[] while cin=gets x,y=cin.split(" ").map(&:to_i) a+=[y-x > 0 ? y-x : -1] a.uniq! if a.size>1 puts -1 exit elsif a[0]==-1 puts -1 exit end end p a[0]