using namespace std;
int a[110][3];
int main()
{
    int t;
    cin >>t;
    for(int i = 0; i < t; i ++)
    {
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    int p = 1;
    int ans=0,ans1=0,ans2=0;
    for(int i = 0; i < t; i ++)
    {
        if(a[i][0] == p||a[i][1] == p)
        {
            if(a[i][0]==p)
            {
                p = a[i][1];
            }
            else p = a[i][0];
            
        }
        if(a[i][2]==p)ans ++;
    }
    p = 2;
    for(int i = 0; i < t; i ++)
    {
        if(a[i][0] == p||a[i][1] == p)
        {
            if(a[i][0]==p)
            {
                p = a[i][1];
            }
            else p = a[i][0];
            
        }
        if(a[i][2]==p)ans1 ++;
    }
    p = 3;
    for(int i = 0; i < t; i ++)
    {
        if(a[i][0] == p||a[i][1] == p)
        {
            if(a[i][0]==p)
            {
                p = a[i][1];
            }
            else p = a[i][0];
            
        }
        if(a[i][2]==p)ans2 ++;
    }
    cout << max(max(ans,ans1),ans2) << endl;
}