#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;
const char *fi ="";
const char *fo ="";
const int MAXN = 10000;
const ld EPS = 1e-9;
fstream f;
struct point{
int a,b,c;
};
bool compare (point x,point y){
if (x.c<y.c) return true;
}
int main()
{
//freopen("t.txt","r",stdin);
int t;
int n;
while (1){
cin>>n;
if (n==0) break;
point p[n+1];
for (int i=1;i<=n;i++) {
cin>>p[i].a>>p[i].b;
if (p[i].a<=p[i].b) swap(p[i].a,p[i].b);
p[i].c=p[i].a*p[i].b;
}
sort (p+1,p+n+1,compare);
int l[n+1],MAX=0;
for (int i=1;i<=n;i++ ){
l[i]=1;
for (int j=1;j<i;j++){
if (p[j].a<=p[i].a && p[j].b<=p[i].b){
l[i]=max (l[i],l[j]+1);
if (l[i]>MAX){
MAX=l[i];
}
}
}
}
cout<<MAX<<endl;
}
cout<<"*";
return 0;
//cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";//cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnR5cGVkZWYgcGFpcjxpbnQsaW50PiBpaTsKdHlwZWRlZiB2ZWN0b3I8aWk+IHZpaTsKdHlwZWRlZiB2ZWN0b3I8aW50PiAgdmk7CnR5cGVkZWYgbG9uZyBkb3VibGUgbGQ7CnR5cGVkZWYgbG9uZyBsb25nIGxsOwpjb25zdCBjaGFyICpmaSA9IiI7CmNvbnN0IGNoYXIgKmZvID0iIjsKY29uc3QgaW50ICBNQVhOID0gMTAwMDA7CmNvbnN0IGxkIEVQUyA9IDFlLTk7CmZzdHJlYW0gZjsKCgpzdHJ1Y3QgcG9pbnR7CgogICAgaW50IGEsYixjOwoKfTsKCmJvb2wgY29tcGFyZSAocG9pbnQgeCxwb2ludCB5KXsKICAgIGlmICh4LmM8eS5jKSByZXR1cm4gdHJ1ZTsKfQoKaW50IG1haW4oKQp7CgkvL2ZyZW9wZW4oInQudHh0IiwiciIsc3RkaW4pOwogICAgaW50IHQ7CiAgICBpbnQgbjsKICAgIHdoaWxlICgxKXsKICAgICAgICBjaW4+Pm47CiAgICAgICAgaWYgKG49PTApIGJyZWFrOwogICAgICAgIHBvaW50IHBbbisxXTsKCiAgICAgICAgZm9yIChpbnQgaT0xO2k8PW47aSsrKSB7CiAgICAgICAgICAgIGNpbj4+cFtpXS5hPj5wW2ldLmI7CiAgICAgICAgICAgIGlmIChwW2ldLmE8PXBbaV0uYikgc3dhcChwW2ldLmEscFtpXS5iKTsKICAgICAgICAgICAgcFtpXS5jPXBbaV0uYSpwW2ldLmI7CgogICAgICAgIH0KCiAgICAgICAgc29ydCAocCsxLHArbisxLGNvbXBhcmUpOwogICAgICAgIGludCBsW24rMV0sTUFYPTA7CgogICAgICAgIGZvciAoaW50IGk9MTtpPD1uO2krKyApewogICAgICAgICAgICBsW2ldPTE7CiAgICAgICAgICAgIGZvciAoaW50IGo9MTtqPGk7aisrKXsKCiAgICAgICAgICAgICAgICBpZiAocFtqXS5hPD1wW2ldLmEgJiYgcFtqXS5iPD1wW2ldLmIpewogICAgICAgICAgICAgICAgICAgIGxbaV09bWF4IChsW2ldLGxbal0rMSk7CiAgICAgICAgICAgICAgICAgICAgaWYgKGxbaV0+TUFYKXsKICAgICAgICAgICAgICAgICAgICAgICAgTUFYPWxbaV07CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgfQoKICAgICAgICB9CiAgICAgICAgY291dDw8TUFYPDxlbmRsOwoKCiAgICB9CiAgICBjb3V0PDwiKiI7CiAgICByZXR1cm4gMDsKCS8vY291dCA8PCAiXG5UaW1lIGVsYXBzZWQ6ICIgPDwgMTAwMCAqIGNsb2NrKCkgLyBDTE9DS1NfUEVSX1NFQyA8PCAibXNcbiI7Ly9jb3V0IDw8ICJcblRpbWUgZWxhcHNlZDogIiA8PCAxMDAwICogY2xvY2soKSAvIENMT0NLU19QRVJfU0VDIDw8ICJtc1xuIjsKfQo=