/*
题意:给出n个箱子,箱子可以放在箱子里边,但是要满足放在里边的箱子的长要小于外边的长,宽要满足小于外边的宽,高要满足小于外边的高。求露在外边的箱子最多有多少个。
思路:思路:最小路径覆盖,如果满足条件:wi < wj , li < lj , and hi < hj,那么i->j连边,然后就是求最大匹配。
最小路径覆盖=顶点数-最大匹配。
*/
#include "stdio.h"
#include "string.h"
#include "algorithm"
using namespace std;
const int maxn = 505;
const int inf = 1<<30;
int n;
int map[maxn][maxn];
int cx[maxn],cy[maxn];
bool vis[maxn];
struct Node
{
int w,l,h;
}doll[maxn];
bool cmp( Node a, Node b )
{
return a.w < b.w ;
}
int findpath( int u )
{
int i,j;
for( i = 1; i <= n; i++ )
{
if( map[u][i] && !vis[i] )
{
vis[i] = 1;
if( cy[i] == -1 || findpath( cy[i] ) )
{
cy[i] = u;
cx[u] = i;
return true;
}
}
}
return false;
}
int MaxMatch()
{
int ans = 0;
int i,j;
//memset(cx,-1,sizeof(cx));
//memset(cy,-1,sizeof(cy));
for( i = 1; i <= n; i++ ) //初始化
{
cx[i] = cy[i] = -1;
}
for( i = 1; i <= n; i ++ )
{
if( cx[i] == -1 )
{
//memset(vis,0,sizeof(vis));
for( j = 1; j <= n; j++ ) //初始化
{
vis[j] = 0;
}
ans += findpath(i);
}
}
return ans;
}
int main()
{
int i,j;
while( scanf("%d",&n)!=EOF , n )
{
// memset(map,0,sizeof(map));
for( i = 1; i <= n; i ++ ) //初始化
{
for( j = 1; j <= n; j ++ )
{
map[i][j] = 0;
}
}
for( i = 1; i <= n; i ++ )
{
scanf("%d%d%d",&doll[i].w,&doll[i].l,&doll[i].h );
}
sort( doll+1,doll+n+1,cmp );
for( i = 1; i <= n; i ++ )
{
for( j = 1; j <= i; j ++ )
{
if( doll[j].w < doll[i].w && doll[j].l < doll[i].l && doll[j].h < doll[i].h )
{
map[i][j] = 1;
}
}
}
printf("%d\n",n-MaxMatch() );
}
return 0;
}