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

int comp(const void *a, const void *b)
{
    int x, y;
    x = *(int *)a;
    y = *(int *)b;
    
    return (x - y);
}

int main(void)
{
    int n;
    int i, j;
    int groupA[1024], groupB[1024];
    int h, m, s, hh, mm, ss;
    int ans;
    int prev;
    
    while (1){
        scanf("%d", &n);
        
        if (n == 0){
            break;
        }
        
        for (i = 0; i < n; i++){
            scanf("%d:%d:%d %d:%d:%d", &h, &m, &s, &hh, &mm, &ss);
            groupA[i] = h * 3600 + m * 60 + s;
            groupB[i] = hh * 3600 + m * 60 + s;
        }
        groupA[n] = INT_MAX;
        groupB[n] = INT_MAX;
        
        qsort(groupA, n + 1, sizeof(int), comp);
        qsort(groupB, n + 1, sizeof(int), comp);
        
        ans = i = j = 0;
        prev = 0;
        
        while (groupA[i] != INT_MAX && groupB[j] != INT_MAX){
            if (groupA[i] < groupB[j]){
                i++;
                if (prev == 0){
                    ans++;
                }
                else {
                    prev--;
                }
            }
            else {
                j++;
                prev++;
            }
        }
        
        printf("%d\n", ans);
    }
    
    return (0);
}