M(int*a){return*1[&a]-*a;}L(t){return t/100*60+t%100;}n,p,q,e[999],m,k,s,t,i,x;main(){for(;scanf("%d%d%d",&n,&p,&q)*n;printf("%d\n",n&&q-p>x?q-p:x)){p=L(p);q=L(q);m=x=0;for(i=n;i--;)for(scanf("%d",&k);k--;e[m++]=L(s)*2+1,e[m++]=L(t)*2)scanf("%d%d",&s,&t);for(qsort(e,m,4,M);m--&&(t=e[m]/2)<=q;)e[m]%2?!--n&&t-p>x?x=t-p:0:!n++?p=e[m]/2:0;}}