n=gets.to_i q=[]; while cin=gets x,y=cin.split(" ").map(&:to_i) q+=[x+y*4]; end t=q.max p q.inject(0){|s,e| if (t-e)%2==1 p -1;exit end s+(t-e)/2}