l[999],s[999],f[999],u,v,a,b;main(n){for(gets(l);~scanf("%d%d",l+n,s+n);++n);for(;u++