x[1010],i;long long m,t,r;main(a,b){for(gets(x);~scanf("%d%d",&a,&b);x[i++]=t=a+4*b,m=m<t?t:m);for(;i--&~r%2;r+=m-x[i]);i=!printf("%Ld\n",r%2?-1:r/2);}