#include<stdio.h>
int main(void){
	int n,hs,ms,ss,he,me,se;
	int i,j,ans,start,end;

	while(1){
		scanf("%d",&n);
		if(n==0){break;}
		int train[86400]={};
		ans=0;
		for(i=0;i<n;i++){
			scanf("%d:%d:%d %d:%d:%d",&hs,&ms,&ss,&he,&me,&se);
			start=3600*hs+60*ms+ss;
			end=3600*he+60*me+se;
			for(j=start;j<end;j++){
				train[j]++;
				if(train[j]>ans){ans=train[j];}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}