long n,m;a[999],s,x;main(p){for(gets(&p);~scanf("%d%d",&x,&p);m=x>m?x:m)a[s++]=x+=p*4;for(;s&~n%2;n+=m-a[--s]);s=!printf("%ld",n&1?-1:n/2);}