a=gets.to_i.times.map{eval gets.split*'+4*'} m=a.min s=0 a.map{|e|d=e-m;d&1>0&&(s=-1)&&break;s+=d/2} p s