/*机智sort二维转一维*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 50010
using namespace std;
int n,s,num,c[maxn*];
struct node
{
int l,r;
}a[maxn*];
int cmp(const node &x,const node &y)
{
if(x.l==y.l)return x.r>y.r;
return x.l<y.l;
}
int init()
{
int x=;char s=getchar();
while(s<''||s>'')s=getchar();
while(s>=''&&s<=''){x=x*+s-'';s=getchar();}
return x;
}
void LIS()
{
for(int i=;i<=num;i++)
{
int x=a[i].r;
if(x>c[s])
{
c[++s]=x;continue;
}
int p=lower_bound(c+,c++s,x)-c;
c[p]=x;
}
}
int main()
{
n=init();
int x,y,z;
for(int i=;i<=n;i++)
{
x=init();y=init();z=init();
a[++num].l=x;a[num].r=y;
a[++num].l=y;a[num].r=x;
a[++num].l=x;a[num].r=z;
a[++num].l=z;a[num].r=x;
a[++num].l=y;a[num].r=z;
a[++num].l=z;a[num].r=y;
}
sort(a+,a++num,cmp);
LIS();
printf("%d\n",s);
return ;
}