// AOJ 2013: Osaki
// 2017.11.1 bal4u@uu
// 2017.12.30

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

typedef struct { int t; int a; } T;
T tbl[20005]; int sz; 
char buf[30], *p;
short f[86400];

int in()
{
	int n;
	n = *p++ & 0xf;
	n = 10*n + (*p++ & 0xf);
	p++;
	return n;
}

int cmp(T *a, T *b) { return a->t - b->t; }

int solve1(int n)
{
	int i, h, m, s, ans;
	T *tp;

	tp = tbl, sz = n << 1;
	while (n--) {
		fgets(p=buf, 30, stdin);
		h = in(), m = in(), s = in();
		tp->t = (((((h<<6)+m)<<6)+s)<<1)+1, tp->a = 1;
		tp++;
		
		h = in(), m = in(), s = in();
		tp->t = ((((h<<6)+m)<<6)+s)<<1, tp->a = -1;
		tp++;
	}

	qsort(tbl, sz, sizeof(T), cmp);
	
	ans = s = 0;
	for (i = 0; i < sz; i++) {
		s += tbl[i].a;
		if (s > ans) ans = s;
	}
	return ans;
}

int solve2(int n)
{
	int i, h, m, s, t, ans;

	memset(f, 0, sizeof(f));
	while (n--) {
		fgets(p=buf, 30, stdin);
		h = in(), m = in(), s = in();
		t = ((h*60)+m)*60+s, f[t]++;

		h = in(), m = in(), s = in();
		t = ((h*60)+m)*60+s, f[t]--;
	}

	ans = t = 0;
	for (ans = 0, i = 0; i < 86400; i++) {
		t += f[i];
		if (t > ans) ans = t;
	}
	return ans;
}

int main()
{
	int n;

	while (fgets(buf, 10, stdin) && *buf != '0') {
		n = atoi(buf);
		if (n <= 5000) printf("%d\n", solve1(n));
		else           printf("%d\n", solve2(n));
	}
	return 0;
}