Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		n := io.NextInt()
		if n == 0 {
			break
		}
		accum := make([]int, 86401)
		for i := 0; i < n; i++ {
			s, e := io.Next(), io.Next()
			hs, _ := strconv.Atoi(s[:2])
			ms, _ := strconv.Atoi(s[3:5])
			ss, _ := strconv.Atoi(s[6:8])
			accum[hs*60*60+ms*60+ss]++
			he, _ := strconv.Atoi(e[:2])
			me, _ := strconv.Atoi(e[3:5])
			se, _ := strconv.Atoi(e[6:8])
			accum[he*60*60+me*60+se]--
		}
		ans := 0
		for i := 1; i < 86401; i++ {
			accum[i] += accum[i-1]
			ans = intMax(accum[i], ans)
		}
		io.Println(ans)
	}
}

func intMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

C++: #include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int64 to_num(string s) {
  int64 ret = 0;
  REP(i, s.size()) {
    if (s[i] == ':') continue;
    ret = ret*10 + s[i]-'0';
  }
  return ret;
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
  int64 n;
  while (cin >> n && n) {
    vector<int64> sum(1000000, 0);
    REP(i, n) {
      string s, e;
      cin >> s >> e;
      sum[to_num(s)]++;
      sum[to_num(e)]--;
    }
    int64 res = sum[0];
    REP(i, 1000000-1) {
      sum[i+1] += sum[i];
      chmax(res, sum[i+1]);
    }
    cout << res << endl;
  }
}

C++: #include<iostream>
#include<string>
#include<queue>
using namespace std;
int main(){
  while(1){
    int n;
    string a[10001],b;
    queue<string> c;
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin>>a[i]>>b;
      c.push(b);
    }
    int cnt=0;
    for(int i=0;i<n;i++){
      if(a[i]<=c.front()){
	c.pop();
      }else cnt++;
    }
    cout<<cnt<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <map>
using namespace std;
int main() {
	int n;
	std::map<int, int> tv;
	for (;;) {
		cin >> n;
		if (!n) break;
		for (int i = 0; i < n; ++i) {
			int h, m, s1, s2;
			scanf("%d:%d:%d", &h, &m, &s1);
			m += h * 60;
			s1 += m * 60;
			scanf("%d:%d:%d", &h, &m, &s2);
			m += h * 60;
			s2 += m * 60;
			++tv[s1];
			--tv[s2];
		}
		int c = 0, max = 0;
		for (auto i : tv) {
			c += i.second;
			if (max < c) max = c;
		}
		std::cout << max << std::endl;
	}
	return 0;
}

C++: #include<complex>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<ctime>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<deque>
#include<queue>
#include<climits>
#include<list>
#include<stack>
#include<ctime>
#define all(n) n.begin(),n.end()
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define pb push_back
#define INF (1<<27)
#define EPS 1e-10
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define MAX_N 1001000
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> Pp;
typedef pair<P,P> PP;
typedef unsigned long long ull;
typedef long long ll;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};

int get_time(string s){
  for(int i=0;i<s.length();i++)if(s[i] == ':')s[i] = ' ';
  stringstream ss;
  ss << s;
  int three[3];
  ss >> three[0] >> three[1] >> three[2];
 
  int sum = 0;
  sum += three[0]*60*60 + three[1]*60 + three[2];
  return sum;
}

bool cmp(const P &p,const P &q){
  if(p.F != q.F)return p.F < q.F;
  return p.F < q.S;
}

template <class T>
class RMQ_segment{
private:
  int n;
  T dat[2*MAX_N-1];
public:
  void init(int n_){
    n = 1;
    while(n<n_)n*=2;
    for(int i=0;i<2*n-1;i++)dat[i] = 0;
  }

  void update(int k,T a){
    k += n-1;
    dat[k] = a;
    while(k > 0){
      k = (k-1)/2;
      dat[k] = max(dat[k*2+1],dat[k*2+2]);
    }
  }

  T _query(int a,int b,int k,int l,int r){
    if(r<=a || b<=l)return 0;
    else if(a<=l && r<=b)return dat[k];

    T vl = _query(a,b,k*2+1,l,(l+r)/2);
    T vr = _query(a,b,k*2+2,(l+r)/2,r);
    return max(vl,vr);
  }

  T query(int a,int b){
    return _query(a,b,0,0,n);
  }
};


int main(){
  int n;
  //clock_t start,end;
  //start = clock(); 
  
  while(cin >> n && n){  
    vector<P> vec;
    vector<P> sor;
    rep(i,n){
      string st,ed;
      cin >> st >> ed;
      vec.pb(P(get_time(st),get_time(ed)));
      sor.pb(P(get_time(ed)-get_time(st),i));
    }
    sort(all(sor),cmp);
    //cout<< "---------" << endl;
    //rep(i,n)cout<< vec[i].F << " " << vec[i].S << endl;
    //cout << "--------" << endl;
    RMQ_segment<int> rmq;
    rmq.init(get_time("24:00:01"));
   
    rep(i,n){
      int index = sor[i].S;
      int res = rmq.query(vec[index].F,vec[index].S);
      rmq.update(vec[index].S-1,res+1);
    }
    cout << rmq.query(0,get_time("24:00:01")) << endl;
  }
  //end = clock();
  //cout << setiosflags(ios::fixed) << setprecision(10) << (double)(end-start)/CLOCKS_PER_SEC << endl;
return 0;
}



/*
Way to check the time of processing speed

clock_t start,end;
start = clock();

------function-------

end = clock();
cout << setiosflags(ios::fixed) << setprecision(10) << (double)(end-start)/CLOCKS_PER_SEC << endl;


*/