//题目类型:二分匹配-最小路径覆盖
//建图:如果后一个垃圾的位置可以通过前一个垃圾的位置可达,则建立一条边
#include <iostream>
//#include <conio.h>
using namespace std;
#define arraysize 25
typedef struct garbage
{
int row;
int col;
}garbage;
garbage garbages[arraysize*arraysize];
int map[arraysize*arraysize][arraysize*arraysize];
bool final[arraysize*arraysize];
int match[arraysize*arraysize];
int ncount;
bool DFS(int p)
{
int i,j;
int t;
for(i=1;i<=ncount;++i)
{
if(map[p][i] && !final[i])
{
final[i] = true;
t = match[i];
match[i] = p;
if(t== 0 || DFS(t)) return true;
match[i] = t;
}
}
return false;
}
int mat()
{
int i,j;
int maxmatch = 0;
for(i=1;i<=ncount;++i)
{
memset(final,0,sizeof(final));
if(DFS(i)) maxmatch++;
}
return maxmatch;
}
int main()
{
//freopen("1.txt","r",stdin);
int i,j;
int row,col;
while(cin>>row>>col)
{
if(row==-1 && col==-1)
break;
memset(map,0,sizeof(map));
memset(match,0,sizeof(match));
ncount = 1;
garbages[ncount].row = row;
garbages[ncount].col = col;
while(cin>>row>>col)
{
if(row==0 && col==0)
break;
ncount++;
garbages[ncount].row = row;
garbages[ncount].col = col;
}
for(i=1;i<=ncount;++i)
{
for(j=i+1;j<=ncount;++j)
{
if(garbages[j].col>=garbages[i].col)
map[i][j] = 1;
}
}
cout<<(ncount-mat())<<endl;
}
//getch();
return 0;
}