#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int change_s(int h,int m,int s){
  return (h*3600+m*60+s);
}

int main(void)
{
  int i,j;
  int n,c;
  int dh[10000],dm[10000],ds[10000];
  int ah[10000],am[10000],as[10000];
  int min,tmp,minnum,maxhour;

  while(1){
    scanf("%d ",&n);
    if(n==0)break;

    maxhour = change_s(24,60,60);

    for(i=0;i<n;i++){
      scanf("%d:%d:%d %d:%d:%d ",&dh[i],&dm[i],&ds[i],&ah[i],&am[i],&as[i]);
    }     

    for(i=0;i<n;i++){
      if(ah[i]>=0){
      min = maxhour;
      minnum = -1;

      for(j=0;j<n;j++){
	if(i!=j){
	tmp = change_s(dh[j],dm[j],ds[j]) - change_s(ah[i],am[i],as[i]);
	if(tmp >= 0 && tmp <min){
	  min = tmp;
	  minnum = j;
	}
	}
      }
      if(minnum>=0){
	  dh[minnum]=dh[i];
	  dm[minnum]=dm[i];
	  ds[minnum]=ds[i];
	  ah[i]=25;
	  dh[i]=-1;
      }
      }
    }

    c = 0;
    for(i=0;i<n;i++){
      if(dh[i]>=0)c++;
    }
    printf("%d\n",c);
  }
  return 0;
}