// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 10000000 + 13

using namespace std;

const double EPS = 1E-9;

vector <int > a[100001];
int c[100001];

void findCol (int v) {
    bool o1 = false, o2 = false, o3 = false;

    for (int i = 0;  i < a[v].size(); i++)
        switch (c[a[v][i]]) {
            case 0: o1 = true; break;
            case 1: o2 = true; break;
            case 2: o3 = true; break;
        }

    if (!o1) c[v] = 0;
    else if (!o2) c[v] = 1;
    else if (!o3) c[v] = 2;
    else c[v] = 2;
}

int main()
{
    int n, m, x, y, z;

    cin >> n >> m;

    for (int i = 0; i < n; i++)
        c[i] = -1;

    for (int i = 0; i < m; i++) {
        cin >> x >> y >> z;

        x--, y--, z--;

        a[x].push_back (y);
        a[x].push_back (z);

        a[y].push_back (x);
        a[y].push_back (z);

        a[z].push_back (x);
        a[z].push_back (y);
    }

    for (int i = 0; i < n; i++)
        findCol (i);

    for (int i = 0; i < n; i++)
        cout << c[i] + 1 << " ";

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 10000000 + 13

using namespace std;

const double EPS = 1E-9;

vector <int > a[200001];
int c[200001];

void findCol (int v) {
    bool o1 = false, o2 = false, o3 = false;
    for (int i = 0;  i < a[v].size(); i++)
        switch (c[a[v][i]]) {
            case 0: o1 = true; break;
            case 1: o2 = true; break;
            case 2: o3 = true; break;
        }

    if (!o1) c[v] = 0;
    else if (!o2) c[v] = 1;
    else if (!o3) c[v] = 2;
    else c[v] = 1;
}

int main()
{
    int n, m, x, y, z;

    cin >> n >> m;

    for (int i = 0; i < n; i++)
        c[i] = -1;

    for (int i = 0; i < m; i++) {
        cin >> x >> y >> z;

        x--, y--, z--;

        a[x].push_back (y);
        a[x].push_back (z);

        a[y].push_back (x);
        a[y].push_back (z);

        a[z].push_back (x);
        a[z].push_back (y);
    }

    for (int i = 0; i < n; i++)
        if (c[i] == -1)
            findCol (i);

    for (int i = 0; i < n; i++)
        if (c[i] == -1)
            findCol (i);

    for (int i = 0; i < n; i++)
        cout << c[i] + 1 << " ";

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 10000000 + 13

using namespace std;

const double EPS = 1E-9;

vector <int > a[100001];
int c[100001];

int main()
{
    int n, m, x, y, z;

    cin >> n >> m;

    for (int i = 0; i < m; i++) {
        cin >> x >> y >> z;

        if (c[x] == 1) c[y] = 2, c[z] = 3;
        else if (c[x] == 2) c[y] = 1, c[z] = 3;
        else if (c[x] == 3) c[y] = 1, c[z] = 2;

        else if (c[y] == 1) c[x] = 2, c[z] = 3;
        else if (c[y] == 2) c[x] = 1, c[z] = 3;
        else if (c[y] == 3) c[x] = 1, c[z] = 2;

        else if (c[z] == 1) c[x] = 2, c[y] = 3;
        else if (c[z] == 2) c[x] = 1, c[y] = 3;
        else if (c[z] == 3) c[x] = 1, c[y] = 2;

        else c[x] = 1, c[y] = 2, c[z] = 3;
    }

    for (int i = 0; i < n; i++)
        cout << c[i + 1] << " ";

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 10000000 + 13

using namespace std;

const double EPS = 1E-9;

vector <int > a[100001];
int c[100001];

bool cmp (vector <int > A, vector <int > B) {
    return (A.size() > B.size());
}

void findCol (int v) {
    bool o1 = false, o2 = false, o3 = false;
    for (int i = 0;  i < a[v].size(); i++)
        switch (c[a[v][i]]) {
            case 0: o1 = true; break;
            case 1: o2 = true; break;
            case 2: o3 = true; break;
        }

    if (!o1) c[v] = 0;
    if (!o2) c[v] = 1;
    if (!o3) c[v] = 2;
}

int main()
{
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);

    vector <int > xx, yy, zz;
    int n, m, x, y, z;

    cin >> n >> m;

    for (int i = 0; i < n; i++)
        c[i] = -1;

    for (int i = 0; i < m; i++) {
        cin >> x >> y >> z;

        x--, y--, z--;

        xx.push_back (x);
        yy.push_back (y);
        zz.push_back (z);

        a[x].push_back (y);
        a[x].push_back (z);

        a[y].push_back (x);
        a[y].push_back (z);

        a[z].push_back (x);
        a[z].push_back (y);
    }

    for (int i = 0; i < n; i++) {
        if (c[i] == -1) {
            findCol (i);
        }
    }

    for (int i = 0; i < n; i++)
        cout << c[i] + 1 << " ";

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 10000000 + 13

using namespace std;

const double EPS = 1E-9;

vector <int > a[100001];
int c[100001];

void dfs (int v, int col) {
    c[v] = col;

    for (int i = 0; i < a[v].size() - 1; i++) {
        if (c[a[v][i]] == -1 && c[a[v][i + 1]] == -1)
            dfs (a[v][i], (col + 1) % 3),
            dfs (a[v][i + 1], (col + 2) % 3);
    }
}

int main()
{
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);

    int n, m, x, y, z;

    cin >> n >> m;

    for (int i = 0; i < n; i++)
        c[i] = -1;

    for (int i = 0; i < m; i++) {
        cin >> x >> y >> z;
        x--, y--, z--;
        a[x].push_back (y);
        a[x].push_back (z);
        a[y].push_back (x);
        a[y].push_back (z);
        a[z].push_back (x);
        a[z].push_back (y);
    }

    for (int i = 0; i < n; i++)
        if (c[i] == -1)
            dfs (i, 0);

    for (int i = 0; i < n; i++)
        cout << c[i] + 1 << " ";
    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 10000000 + 13

using namespace std;

const double EPS = 1E-9;

vector <int > a[100001];
int c[100001];

void findCol (int v) {
    bool o1 = false, o2 = false, o3 = false;
    for (int i = 0;  i < a[v].size(); i++)
        switch (c[a[v][i]]) {
            case 0: o1 = true; break;
            case 1: o2 = true; break;
            case 2: o3 = true; break;
        }

    if (!o1) c[v] = 0;
    else if (!o2) c[v] = 1;
    else if (!o3) c[v] = 2;
    else c[v] = 2;
}

int main()
{
    int n, m, x, y, z;

    cin >> n >> m;

    for (int i = 0; i < n; i++)
        c[i] = -1;

    for (int i = 0; i < m; i++) {
        cin >> x >> y >> z;

        x--, y--, z--;

        a[x].push_back (y);
        a[x].push_back (z);

        a[y].push_back (x);
        a[y].push_back (z);

        a[z].push_back (x);
        a[z].push_back (y);
    }

    for (int i = 0; i < n; i++)
        if (c[i] == -1)
            findCol (i);

    for (int i = 0; i < n; i++)
        cout << c[i] + 1 << " ";

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int map[100006][3];
bool visit[100006][3];
int hash[10006];
int n,m;
int ok(int x,int y,int num)
{
    int sum=0;
    for(int i = 0;i<=2;i++ )
    {
        if((hash[map[x][i]]!=num || hash[map[x][i]]==0)&& i!=y)
        {
            sum++;
        }
    }
    if(sum>=2) return 1;
    return 0;
}

void dfs()
{
    for(int i=0;i<m;i++)
    {
       for(int j = 0;j <=2; j ++)
       {
           if(!visit[i][j] && hash[map[i][j]] == 0)
           {
               visit[i][j] = 1;
               for(int k = 1;k<=3;k++ )
               {
                   if(ok(i,j,k)==1){
                    hash[map[i][j]] = k;
                    break;
                   }
               }
           }
       }
    }
}
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        memset(hash,0,sizeof(hash));
        memset(visit,0,sizeof(visit));
        memset(map1,0,sizeof(map1));
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<3;j++)
            {
                scanf("%d",&map[i][j]);
                if(i==0)
                {
                    if(j==0){
                         hash[map[i][j]] = 1;
                    visit[i][j] = 1;
                    }
                    if(j==1)
                    {
                         hash[map[i][j]] = 2;
                    visit[i][j] = 1;
                    }
                    if(j==2)
                    {
                         hash[map[i][j]] = 3;
                        visit[i][j] = 1;
                    }
                }
            }
        }
        dfs();
        for(int i=1;i<=n;i++)
        {
            printf("%d%c",hash[i],i==n?'\n':' ');
        }
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstdlib>
using namespace std;
int map[900009][3];
int hash[900009];
struct node
{
    int x,y;
} p[900009*3];
int n,m,yes = 0;

int ok(int k,int x)
{
    int sum=0;
    for(int i=0; i<3; i++)
    {
        if( (hash[ map[p[k].x][i] ] != x || hash[ map[p[k].x][i] ] == 0 ) && p[k].y != i ) sum++;
    }
    if(sum==2) return 1;
    return 0;
}
void out()
{
    if(yes>=1) return ;
    for(int i=1; i<=n; i++)
    {
        printf("%d%c",hash[i],i==n?'\n':' ');
    }
    yes++;
}

void dfs(int k,int count)
{
    if(count == n*m )
    {
        out();
        return ;
    }
    if(yes>=1) break;
    if(hash[ map[ p[k].x ][ p[k].y ] ] != 0)
    {
        dfs(k+1,++count);
    }
    else
     {
        for(int i=1; i<=3; i++)
        {
            int cur = hash[  map[ p[k].x ][ p[k].y ] ];
            if( ok(k,i) == 1 && cur != i)
            {
                hash[ map[p[k].x][p[k].y] ] = i;
                dfs(k+1,++count);
                hash[ map[p[k].x][p[k].y] ] = cur;
            }
        }
    }
}
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        yes = 0;
        memset(hash,0,sizeof(hash));
        int top = 0;
        for(int i=0; i<m; i++)
            for(int j=0; j<3; j++)
            {
                scanf("%d",&map[i][j]);
                p[top].x = i;
                p[top++].y = j;
            }
        dfs(0,0);
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstdlib>
using namespace std;
int map[100009][3];
int hash[300009];
struct node
{
    int x,y;
} p[300003];
int n,m,yes = 0;
void out()
{
    if(yes>=1) return ;
    for(int i=1; i<=n; i++)
    {
        printf("%d%c",hash[i],i==n?'\n':' ');
    }
    yes++;
}
void dfs(int k,int count)
{
    if(yes>=1)return;
    if(count == n*m )
    {
        out();
        return ;
    }
    if(hash[ map[ p[k].x ][ p[k].y ] ] != 0)
    {
        dfs(k+1,++count);
    }
    else
    {
        for(int i=1; i<=3; i++)
        {
            int cur = hash[  map[ p[k].x ][ p[k].y ] ];
            if( cur != i)
            {
                int sum = 0;
                for(int j=0; j<3; j++)
                {
                    if( (hash[ map[p[k].x][j] ] != i || hash[ map[p[k].x][j] ] == 0 ) && p[k].y != j ) sum++;
                }
                if(sum>=2)
                {
                     hash[ map[p[k].x][p[k].y] ] = i;
                     dfs(k+1,++count);
                     hash[ map[p[k].x][p[k].y] ] = cur;
                }
            }
        }
    }
}
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        yes = 0;
        memset(hash,0,sizeof(hash));
        int top = 0;
        for(int i=0; i<m; i++)
            for(int j=0; j<3; j++)
            {
                scanf("%d",&map[i][j]);
                p[top].x = i;
                p[top++].y = j;
            }
        dfs(0,0);
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int map[100006][3];
int map1[100006][3];
bool visit[100006][3];
int hash[10006];
  int n,m;
int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};

int ok(int x,int y,int num)
{
    int sum=0;
    for(int i = 0;i<=2;i++ )
    {
        if((hash[map[x][i]]!=num || hash[map[x][i]]==0)&& i!=y)
        {
            sum++;
        }
    }
    if(sum>=2) return 1;
    return 0;
}

void dfs()
{
    for(int i=0;i<m;i++)
    {
       for(int j = 0;j <=2; j ++)
       {
           if(!visit[i][j] && hash[map[i][j]] == 0)
           {
               visit[i][j] = 1;
               for(int k = 1;k<=3;k++ )
               {
                   if(ok(i,j,k)==1){
                    hash[map[i][j]] = k;
                    break;
                   }
               }
           }
       }
    }
}
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        memset(hash,0,sizeof(hash));
        memset(visit,0,sizeof(visit));
        memset(map1,0,sizeof(map1));
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<3;j++)
            {
                scanf("%d",&map[i][j]);
                if(i==0)
                {
                    if(j==0){
                         hash[map[i][j]] = 1;
                    visit[i][j] = 1;
                    }
                    if(j==1)
                    {
                         hash[map[i][j]] = 2;
                    visit[i][j] = 1;
                    }
                    if(j==2)
                    {
                         hash[map[i][j]] = 3;
                        visit[i][j] = 1;
                    }
                }
            }
        }
        dfs();
        for(int i=1;i<=n;i++)
        {
            printf("%d%c",hash[i],i==n?'\n':' ');
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int map[100006][3];
bool visit[100006][3];
int hash[10006];
int n,m;
int ok(int x,int y,int num)
{
    int sum=0;
    for(int i = 0; i<=2; i++ )
    {
        if((hash[map[x][i]]!=num || hash[map[x][i]]==0)&& i!=y)
        {
            sum++;
        }
    }
    if(sum>=2) return 1;
    return 0;
}
void dfs()
{
    for(int i=0; i<m; i++)
    {
        for(int j = 0; j <=2; j ++)
        {
            if( !visit[i][j] )
            {
                visit[i][j] = 1;
                if(hash[map[i][j]]==0)
                {
                    for(int k = 1; k<=3; k++ )
                    {
                        if(ok(i,j,k) == 1 )
                        {
                            hash[map[i][j]] = k;
                            break;
                        }
                    }
                }

            }
        }
    }
}
void dfs2()
{
    for(int i=m-1; i>=0; i--)
    {
        for(int j = 0; j <=2; j ++)
        {
            if( !visit[i][j] )
            {
                visit[i][j] = 1;
                if(hash[map[i][j]]==0)
                {
                    for(int k = 1; k<=3; k++ )
                    {
                        if(ok(i,j,k) == 1 )
                        {
                            hash[map[i][j]] = k;
                            break;
                        }
                    }
                }

            }
        }
    }
}
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        memset(hash,0,sizeof(hash));
        memset(visit,0,sizeof(visit));
        for(int i=0; i<m; i++)
        {
            for(int j=0; j<3; j++)
            {
                scanf("%d",&map[i][j]);
                if(i==0)
                {
                    if(j==0)
                    {
                        hash[map[i][j]] = 1;
                        visit[i][j] = 1;
                    }
                    if(j==1)
                    {
                        hash[map[i][j]] = 2;
                        visit[i][j] = 1;
                    }
                    if(j==2)
                    {
                        hash[map[i][j]] = 3;
                        visit[i][j] = 1;
                    }
                }
            }
        }
        dfs();
        dfs2();
        for(int i=1; i<=n; i++)
        {
            printf("%d%c",hash[i],i==n?'\n':' ');
        }
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstdlib>
using namespace std;
int map[100009][3];
int hash[300009];
struct node
{
    int x,y;
} p[300003];
int n,m,yes = 0;
void out()
{
    if(yes>=1) return ;
    for(int i=1; i<=n; i++)
    {
        printf("%d%c",hash[i],i==n?'\n':' ');
    }
    yes++;
}
void dfs(int k,int count)
{
    if(yes>=1)return;
    if(count == n*m )
    {
        out();
        return ;
    }
    for(int i=1; i<=3; i++)
    {
        int cur = hash[  map[ p[k].x ][ p[k].y ] ];
        if( cur != i)
        {
            int sum = 0;
            for(int j=0; j<3; j++)
            {
                if( (hash[ map[p[k].x][j] ] != i || hash[ map[p[k].x][j] ] == 0 ) && p[k].y != j ) sum++;
            }
            if(sum>=2)
            {
                hash[ map[p[k].x][p[k].y] ] = i;
                dfs(k+1,++count);
                hash[ map[p[k].x][p[k].y] ] = cur;
            }
            else if(cur!=0)
            {
                dfs(k+1,++count);
            }
        }
    }
}
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        yes = 0;
        memset(hash,0,sizeof(hash));
        int top = 0;
        for(int i=0; i<m; i++)
            for(int j=0; j<3; j++)
            {
                scanf("%d",&map[i][j]);
                p[top].x = i;
                p[top++].y = j;
            }
        dfs(0,0);
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstdlib>
using namespace std;

int map[900009][4];
int hash[900009*4];
struct node
{
    int x,y;
} p[900009*4];

int n,m,yes = 0;

int ok(int k,int x)
{
    int sum=0;
    for(int i=0; i<3; i++)
    {
        if( (hash[ map[p[k].x][i] ] != x || hash[ map[p[k].x][i] ] == 0 ) && p[k].y != i ) sum++;
    }
    if(sum==2) return 1;
    return 0;
}
void out()
{
    if(yes>=1) return ;
    for(int i=1; i<=n; i++)
    {
        printf("%d%c",hash[i],i==n?'\n':' ');
    }
    yes++;
}

void dfs(int k,int count)
{
    if(count == n*m )
    {
        out();
        return ;
    }
    if(yes>=1) return ;
    if(hash[ map[ p[k].x ][ p[k].y ] ] != 0)
    {
        dfs(k+1,++count);
    }
    else
     {
        for(int i=1; i<=3; i++)
        {
            int cur = hash[  map[ p[k].x ][ p[k].y ] ];
            if( ok(k,i) == 1 && cur != i)
            {
                hash[ map[p[k].x][p[k].y] ] = i;
                dfs(k+1,++count);
                hash[ map[p[k].x][p[k].y] ] = cur;
            }
        }
    }
}
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        yes = 0;
        memset(hash,0,sizeof(hash));
        int top = 0;
        for(int i=0; i<m; i++)
            for(int j=0; j<3; j++)
            {
                scanf("%d",&map[i][j]);
                p[top].x = i;
                p[top++].y = j;
            }
        dfs(0,0);
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstdlib>
using namespace std;
int map[900009][3];
int hash[900009];
struct node
{
    int x,y;
} p[900009*3];
int n,m,yes = 0;

int ok(int k,int x)
{
    int sum=0;
    for(int i=0; i<3; i++)
    {
        if( (hash[ map[p[k].x][i] ] != x || hash[ map[p[k].x][i] ] == 0 ) && p[k].y != i ) sum++;
    }
    if(sum==2) return 1;
    return 0;
}
void out()
{
    if(yes>=1) return ;
    for(int i=1; i<=n; i++)
    {
        printf("%d%c",hash[i],i==n?'\n':' ');
    }
    yes++;
}

void dfs(int k,int count)
{
    if(count == n*m )
    {
        out();
        return ;
    }
    if(yes>=1) return ;
    if(hash[ map[ p[k].x ][ p[k].y ] ] != 0)
    {
        dfs(k+1,++count);
    }
    else
     {
        for(int i=1; i<=3; i++)
        {
            int cur = hash[  map[ p[k].x ][ p[k].y ] ];
            if( ok(k,i) == 1 && cur != i)
            {
                hash[ map[p[k].x][p[k].y] ] = i;
                dfs(k+1,++count);
                hash[ map[p[k].x][p[k].y] ] = cur;
            }
        }
    }
}
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        yes = 0;
        memset(hash,0,sizeof(hash));
        int top = 0;
        for(int i=0; i<m; i++)
            for(int j=0; j<3; j++)
            {
                scanf("%d",&map[i][j]);
                p[top].x = i;
                p[top++].y = j;
            }
        dfs(0,0);
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstdlib>
using namespace std;

int map[900009][3];
int hash[900009*3];
struct node
{
    int x,y;
} p[900009*3];

int n,m,yes = 0;

int ok(int k,int x)
{
    int sum=0;
    for(int i=0; i<3; i++)
    {
        if( (hash[ map[p[k].x][i] ] != x || hash[ map[p[k].x][i] ] == 0 ) && p[k].y != i ) sum++;
    }
    if(sum==2) return 1;
    return 0;
}
void out()
{
    if(yes>=1) return ;
    for(int i=1; i<=n; i++)
    {
        printf("%d%c",hash[i],i==n?'\n':' ');
    }
    yes++;
}

void dfs(int k,int count)
{
    if(count == n*m )
    {
        out();
        return ;
    }
    if(yes>=1) return ;
    if(hash[ map[ p[k].x ][ p[k].y ] ] != 0)
    {
        dfs(k+1,++count);
    }
    else
     {
        for(int i=1; i<=3; i++)
        {
            int cur = hash[  map[ p[k].x ][ p[k].y ] ];
            if( ok(k,i) == 1 && cur != i)
            {
                hash[ map[p[k].x][p[k].y] ] = i;
                dfs(k+1,++count);
                hash[ map[p[k].x][p[k].y] ] = cur;
            }
        }
    }
}
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        yes = 0;
        memset(hash,0,sizeof(hash));
        int top = 0;
        for(int i=0; i<m; i++)
            for(int j=0; j<3; j++)
            {
                scanf("%d",&map[i][j]);
                p[top].x = i;
                p[top++].y = j;
            }
        dfs(0,0);
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstdlib>
using namespace std;
int map[900009][3];
int hash[900009];
struct node
{
    int x,y;
} p[900009*3];
int n,m,yes = 0;
void out()
{
    if(yes>=1) return ;
    for(int i=1; i<=n; i++)
    {
        printf("%d%c",hash[i],i==n?'\n':' ');
    }
    yes++;
}
void dfs(int k,int count)
{
    if(yes>=1)return;
    if(count == n*m )
    {
        out();
        return ;
    }
    if(hash[ map[ p[k].x ][ p[k].y ] ] != 0)
    {
        dfs(k+1,++count);
    }
    else
    {
        for(int i=1; i<=3; i++)
        {
            int cur = hash[  map[ p[k].x ][ p[k].y ] ];
            if( cur != i)
            {
                int sum = 0;
                for(int j=0; j<3; j++)
                {
                    if( (hash[ map[p[k].x][j] ] != i || hash[ map[p[k].x][j] ] == 0 ) && p[k].y != j ) sum++;
                }
                if(sum>=2)
                {
                     hash[ map[p[k].x][p[k].y] ] = i;
                     dfs(k+1,++count);
                     hash[ map[p[k].x][p[k].y] ] = cur;
                }
            }
        }
    }
}
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        yes = 0;
        memset(hash,0,sizeof(hash));
        int top = 0;
        for(int i=0; i<m; i++)
            for(int j=0; j<3; j++)
            {
                scanf("%d",&map[i][j]);
                p[top].x = i;
                p[top++].y = j;
            }
        dfs(0,0);
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstdlib>
using namespace std;

int map[100009][4];
int hash[100009*4];
struct node
{
    int x,y;
} p[100009*4];

int n,m,yes = 0;

int ok(int k,int x)
{
    int sum=0;
    for(int i=0; i<3; i++) ///这里还有问题
    {
        if( (hash[ map[p[k].x][i] ] != x || hash[ map[p[k].x][i] ] == 0 ) && p[k].y != i ) sum++;
    }
    if(sum==2) return 1;
    return 0;
}
void out()
{
    if(yes>=1) return ;
    for(int i=1; i<=n; i++)
    {
        printf("%d%c",hash[i],i==n?'\n':' ');
    }
    yes++;
}

void dfs(int k,int count)
{
    if(count == n*m )
    {
        out();
        return ;
    }
    if(yes>=1) return ;
   if(hash[ map[ p[k].x ][ p[k].y ] ]!=0)
    {
        dfs(k+1,++count);
    }
    else
     {
        for(int i=1; i<=3; i++)
        {
            int cur = hash[  map[ p[k].x ][ p[k].y ] ];
            if( ok(k,i)==1 && cur != i)
            {
                hash[ map[p[k].x][p[k].y] ] = i;
                dfs(k+1,++count);
                hash[ map[p[k].x][p[k].y]] = cur;
            }
        }
    }
}
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        yes = 0;
        memset(hash,0,sizeof(hash));
        int top = 0;
        for(int i=0; i<m; i++)
            for(int j=0; j<3; j++)
            {
                scanf("%d",&map[i][j]);
                p[top].x = i;
                p[top++].y = j;
            }
        dfs(0,0);
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstdlib>
using namespace std;
int map[900009][3];
int hash[900009];
struct node
{
    int x,y;
} p[900009*3];
int n,m,yes = 0;

int ok(int k,int x)
{
    int sum=0;
    for(int i=0; i<3; i++)
    {
        if( (hash[ map[p[k].x][i] ] != x || hash[ map[p[k].x][i] ] == 0 ) && p[k].y != i ) sum++;
    }
    if(sum==2) return 1;
    return 0;
}
void out()
{
    if(yes>=1) return ;
    for(int i=1; i<=n; i++)
    {
        printf("%d%c",hash[i],i==n?'\n':' ');
    }
    yes++;
}

void dfs(int k,int count)
{
    if(yes>=1)return;
    if(count == n*m )
    {
        out();
        return ;
    }
    if(hash[ map[ p[k].x ][ p[k].y ] ] != 0)
    {
        dfs(k+1,++count);
    }
    else
     {
        for(int i=1; i<=3; i++)
        {
            int cur = hash[  map[ p[k].x ][ p[k].y ] ];
            if( ok(k,i) == 1 && cur != i)
            {
                hash[ map[p[k].x][p[k].y] ] = i;
                dfs(k+1,++count);
                hash[ map[p[k].x][p[k].y] ] = cur;
            }
        }
    }
}
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        yes = 0;
        memset(hash,0,sizeof(hash));
        int top = 0;
        for(int i=0; i<m; i++)
            for(int j=0; j<3; j++)
            {
                scanf("%d",&map[i][j]);
                p[top].x = i;
                p[top++].y = j;
            }
        dfs(0,0);
    }
    return 0;
}


#define TASKNAME "text"
#include <cstdio>
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <cassert>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <vector>

#define EPS 1e-9
#define INF int(1e9)
#define INFLONG (long long)(1e18)
#define sqr(a) ((a) * (a))
#define all(a) (a).begin(), (a).end()
#define zero(a) memset(a, 0, sizeof(a))
#define abs(a) (((a) < 0) ? -(a) : (a))
#define sz(a) (int)a.size()
#define fst first
#define snd second
#define y1 osrughosduvgarligybakrybrogvba
#define y0 aosfigdalrowgyalsouvgrlvygalri
#define mp make_pair
#define pb push_back
#define next dlkjdslfkdj
#define prev dsdflksdfjl
#define hash lkdfjldskfj
#define pi 3.1415926535897932384626433832795
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <bool> vb;
typedef vector <ll> vll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef vector <pii> vpii;

const int maxn = 1e5 + 10;

int n, m;
int a[maxn][3];
int ans[maxn];
bool used[4];

int main()
{
  #ifdef LocalHost
    freopen(TASKNAME".in", "r", stdin);
    freopen(TASKNAME".out", "w", stdout);
  #endif
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++)
    for (int j = 0; j < 3; j++)
      scanf("%d", &a[i][j]), --a[i][j];
  for (int i = 0; i < m; i++)
  {
    for (int j = 0; j < 4; j++)
      used[j] = 0;
    int cnt = 0;
    for (int j = 0; j < 3; j++)
    {
      if (ans[a[i][j]])
      {
        if (++cnt >= 2)
          assert(0);
        used[ans[a[i][j]]] = 1;
        continue;
      }
      for (int it = 1; it <= 3; it++)
        if (!used[it])
        {
          ans[a[i][j]] = it;
          used[it] = 1;
          break;
        }
    }
  }
  for (int i = 0; i < n; i++)
    printf("%d%c", ans[i], " \n"[i == n - 1]);
  return 0;
}


#define TASKNAME "text"
#include <cstdio>
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <cassert>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <vector>

#define EPS 1e-9
#define INF int(1e9)
#define INFLONG (long long)(1e18)
#define sqr(a) ((a) * (a))
#define all(a) (a).begin(), (a).end()
#define zero(a) memset(a, 0, sizeof(a))
#define abs(a) (((a) < 0) ? -(a) : (a))
#define sz(a) (int)a.size()
#define fst first
#define snd second
#define y1 osrughosduvgarligybakrybrogvba
#define y0 aosfigdalrowgyalsouvgrlvygalri
#define mp make_pair
#define pb push_back
#define next dlkjdslfkdj
#define prev dsdflksdfjl
#define hash lkdfjldskfj
#define pi 3.1415926535897932384626433832795
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <bool> vb;
typedef vector <ll> vll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef vector <pii> vpii;

const int maxn = 2e5 + 100;

int n, m;
int a[maxn][3];
int ans[maxn];
bool used[4];

int main()
{
  #ifdef LocalHost
    freopen(TASKNAME".in", "r", stdin);
    freopen(TASKNAME".out", "w", stdout);
  #endif
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++)
    for (int j = 0; j < 3; j++)
      scanf("%d", &a[i][j]), --a[i][j];
  for (int i = 0; i < m; i++)
  {
    bool found = 0;
    int val = -1;
    for (int j = 0; j < 3; j++)
      if (ans[a[i][j]])
      {
        found = 1;
        val = ans[a[i][j]];
        break;
      }
    if (found)
    {
      assert(1 <= val && val <= 3);
      int now = 1;
      if (now == val)
        ++now;
      for (int j = 0; j < 3; j++)
        if (!ans[a[i][j]])
        {
          ans[a[i][j]] = now++;
          if (now == val)
            ++now;
        }
    }
    else
    {
      for (int j = 0; j < 3; j++)
        ans[a[i][j]] = j + 1;
    }
  }
  for (int i = 0; i < n; i++)
  {
    assert(1 <= ans[i] && ans[i] <= 3);
    printf("%d%c", ans[i], " \n"[i == n - 1]);
  }
  return 0;
}


#define TASKNAME "text"
#include <cstdio>
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <cassert>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <vector>

#define EPS 1e-9
#define INF int(1e9)
#define INFLONG (long long)(1e18)
#define sqr(a) ((a) * (a))
#define all(a) (a).begin(), (a).end()
#define zero(a) memset(a, 0, sizeof(a))
#define abs(a) (((a) < 0) ? -(a) : (a))
#define sz(a) (int)a.size()
#define fst first
#define snd second
#define y1 osrughosduvgarligybakrybrogvba
#define y0 aosfigdalrowgyalsouvgrlvygalri
#define mp make_pair
#define pb push_back
#define next dlkjdslfkdj
#define prev dsdflksdfjl
#define hash lkdfjldskfj
#define pi 3.1415926535897932384626433832795
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <bool> vb;
typedef vector <ll> vll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef vector <pii> vpii;

const int maxn = 1e5 + 10;

int n, m;
int a[maxn][3];
int ans[maxn];

int main()
{
  #ifdef LocalHost
    freopen(TASKNAME".in", "r", stdin);
    freopen(TASKNAME".out", "w", stdout);
  #endif
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++)
    for (int j = 0; j < 3; j++)
      scanf("%d", &a[i][j]), --a[i][j];
  for (int i = 0; i < m; i++)
  {
    vb used(4, 0);
    for (int j = 0; j < 3; j++)
    {
      if (ans[a[i][j]])
      {
        used[ans[a[i][j]]] = 1;
        continue;
      }
      for (int it = 1; it <= 3; it++)
        if (!used[it])
        {
          ans[a[i][j]] = it, used[it] = 1;
          break;
        }
    }
  }
  for (int i = 0; i < n; i++)
    printf("%d%c", ans[i], " \n"[i == n - 1]);
  return 0;
}


#define TASKNAME "text"
#include <cstdio>
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <cassert>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <vector>

#define EPS 1e-9
#define INF int(1e9)
#define INFLONG (long long)(1e18)
#define sqr(a) ((a) * (a))
#define all(a) (a).begin(), (a).end()
#define zero(a) memset(a, 0, sizeof(a))
#define abs(a) (((a) < 0) ? -(a) : (a))
#define sz(a) (int)a.size()
#define fst first
#define snd second
#define y1 osrughosduvgarligybakrybrogvba
#define y0 aosfigdalrowgyalsouvgrlvygalri
#define mp make_pair
#define pb push_back
#define next dlkjdslfkdj
#define prev dsdflksdfjl
#define hash lkdfjldskfj
#define pi 3.1415926535897932384626433832795
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <bool> vb;
typedef vector <ll> vll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef vector <pii> vpii;

const int maxn = 2e5 + 100;

int n, m;
int a[maxn][3];
int ans[maxn];
bool used[4];

int main()
{
  #ifdef LocalHost
    freopen(TASKNAME".in", "r", stdin);
    freopen(TASKNAME".out", "w", stdout);
  #endif
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++)
    for (int j = 0; j < 3; j++)
      scanf("%d", &a[i][j]), --a[i][j];
  for (int i = 0; i < m; i++)
  {
    bool found = 0;
    int val = -1;
    for (int j = 0; j < 3; j++)
      if (ans[a[i][j]])
      {
        found = 1;
        val = ans[a[i][j]];
      }
    if (found)
    {
      assert(1 <= val && val <= 3);
      int now = 1;
      for (int j = 0; j < 3; j++)
        if (!ans[a[i][j]])
        {
          ans[a[i][j]] = now++;
          if (now == val)
            ++now;
        }
    }
    else
    {
      for (int j = 0; j < 3; j++)
        ans[a[i][j]] = j + 1;
    }
  }
  for (int i = 0; i < n; i++)
  {
    assert(1 <= ans[i] && ans[i] <= 3);
    printf("%d%c", ans[i], " \n"[i == n - 1]);
  }
  return 0;
}


#define TASKNAME "text"
#include <cstdio>
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <cassert>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <vector>

#define EPS 1e-9
#define INF int(1e9)
#define INFLONG (long long)(1e18)
#define sqr(a) ((a) * (a))
#define all(a) (a).begin(), (a).end()
#define zero(a) memset(a, 0, sizeof(a))
#define abs(a) (((a) < 0) ? -(a) : (a))
#define sz(a) (int)a.size()
#define fst first
#define snd second
#define y1 osrughosduvgarligybakrybrogvba
#define y0 aosfigdalrowgyalsouvgrlvygalri
#define mp make_pair
#define pb push_back
#define next dlkjdslfkdj
#define prev dsdflksdfjl
#define hash lkdfjldskfj
#define pi 3.1415926535897932384626433832795
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <bool> vb;
typedef vector <ll> vll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef vector <pii> vpii;

const int maxn = 2e5 + 100;

int n, m;
int a[maxn][3];
int ans[maxn];
bool used[4];

int main()
{
  #ifdef LocalHost
    freopen(TASKNAME".in", "r", stdin);
    freopen(TASKNAME".out", "w", stdout);
  #endif
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++)
    for (int j = 0; j < 3; j++)
      scanf("%d", &a[i][j]), --a[i][j];
  for (int i = 0; i < m; i++)
  {
    bool found = 0;
    int val = -1;
    for (int j = 0; j < 3; j++)
      if (ans[a[i][j]])
      {
        found = 1;
        val = ans[a[i][j]];
      }
    if (found)
    {
      assert(1 <= val && val <= 3);
      int now = 1;
      for (int j = 0; j < 3; j++)
        if (!ans[i][j])
        {
          ans[i][j] = now++;
          if (now == val)
            ++now;
        }
    }
    else
    {
      for (int j = 0; j < 3; j++)
        ans[a[i][j]] = j + 1;
    }
  }
  for (int i = 0; i < n; i++)
  {
    assert(1 <= ans[i] && ans[i] <= 3);
    printf("%d%c", ans[i], " \n"[i == n - 1]);
  }
  return 0;
}


/*************************************************************
 * Filename: B_CC
 * Author: Pira
 * Date: 2013-10-15 20:19:05
 **************************************************************/
/** head files*/
/*#pragma comment(linker,"/STACK:102400000,102400000")*/
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;

/** some operate*/
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,l,h) for(int i=(l);i<=(h);++i)
#define DWN(i,h,l) for(int i=(h);i>=(l);--i)
#define foreach(e,x) for(__typeof(x.begin()) e=x.begin();e!=x.end();++e)
#define CLR(arr) memset(arr,0,sizeof(arr))

/** some const*/
#define N 200010
#define PI acos(-1.0)
#define oo 1000000000
#define loo 1000000000000000000LL
/** some alias*/
typedef long long ll;
typedef double db;

int dx[]={0,-1,0,1};
int dy[]={1,0,-1,0};
/** Global variables*/
vector< int> edge[N];
int ok[N][3], out[N];
int n, m, a, b, c;
int dfs(int i)
{
	if( i>n)
	{
		FOR(j,1,n)
			printf("%d%c", out[j],j<n?' ':'\n');
		return 1;
	}
	REP(j,3)
		if( !ok[i][j] )
		{
			out[i] = j + 1;
			REP(k,(int)edge[i].size())
				ok[ edge[i][k] ][j] = 1;
			if( dfs( i+1 ))return 1;
			REP(k,(int)edge[i].size())
				ok[ edge[i][k] ][j] = 0;
		}
	return 0;
}
int main(int argc, char *argv[])
{
	CLR(ok);
	scanf("%d%d", &n, &m);
	FOR(i,1,n)edge[i].clear();
	REP(i,m)
	{
		scanf("%d%d%d", &a, &b, &c);
		edge[a].push_back(b);
		edge[a].push_back(c);
		edge[b].push_back(a);
		edge[b].push_back(c);
		edge[c].push_back(a);
		edge[c].push_back(b);
	}
	dfs(1);
	return 0;
}


/*************************************************************
 * Filename: B_CC
 * Author: Pira
 * Date: 2013-10-15 20:19:05
 **************************************************************/
/** head files*/
/*#pragma comment(linker,"/STACK:102400000,102400000")*/
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;

/** some operate*/
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,l,h) for(int i=(l);i<=(h);++i)
#define DWN(i,h,l) for(int i=(h);i>=(l);--i)
#define foreach(e,x) for(__typeof(x.begin()) e=x.begin();e!=x.end();++e)
#define CLR(arr) memset(arr,0,sizeof(arr))

/** some const*/
#define N 200010
#define PI acos(-1.0)
#define oo 1000000000
#define loo 1000000000000000000LL
/** some alias*/
typedef long long ll;
typedef double db;

int dx[]={0,-1,0,1};
int dy[]={1,0,-1,0};
/** Global variables*/
vector< int> edge[N];
int out[N];
int n, m, a, b, c;
int dfs(int i)
{
	FOR(j,1,3)
	{
		REP(k,(int)edge[i].size())
			if( out[ edge[i][k] ] ==j ) goto end;
		out[i] = j;
		REP(k,(int)edge[i].size())
			if( out[ edge[i][k] ]<=0)
				dfs( edge[i][k] );
		end:;
	}
	return 0;
}
int main(int argc, char *argv[])
{
	scanf("%d%d", &n, &m);
	FOR(i,1,n)edge[i].clear();
	REP(i,m)
	{
		scanf("%d%d%d", &a, &b, &c);
		edge[a].push_back(b);
		edge[a].push_back(c);
		edge[b].push_back(a);
		edge[b].push_back(c);
		edge[c].push_back(a);
		edge[c].push_back(b);
	}
	CLR(out);
	FOR(i,1,n)
		if(!out[i])dfs(i);
	FOR(i,1,n)
		printf("%d%c", out[i],i<n?' ':'\n');
	return 0;
}


/*************************************************************
 * Filename: B_CC
 * Author: Pira
 * Date: 2013-10-15 20:19:05
 **************************************************************/
/** head files*/
/*#pragma comment(linker,"/STACK:102400000,102400000")*/
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;

/** some operate*/
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,l,h) for(int i=(l);i<=(h);++i)
#define DWN(i,h,l) for(int i=(h);i>=(l);--i)
#define foreach(e,x) for(__typeof(x.begin()) e=x.begin();e!=x.end();++e)
#define CLR(arr) memset(arr,0,sizeof(arr))

/** some const*/
#define N 200010
#define PI acos(-1.0)
#define oo 1000000000
#define loo 1000000000000000000LL
/** some alias*/
typedef long long ll;
typedef double db;

int dx[]={0,-1,0,1};
int dy[]={1,0,-1,0};
/** Global variables*/
vector< int> edge[N];
int out[N];
int n, m, a, b, c;
int dfs(int i)
{
	if( i>n)
	{
		FOR(j,1,n)
			printf("%d%c", out[j],j<n?' ':'\n');
		return 1;
	}
	FOR(j,1,3)
	{
		REP(k,(int)edge[i].size())
			if( out[ edge[i][k] ] ==j ) goto end;
		out[i] = j;
		if( dfs( i+1 ))return 1;
		out[i] = 0;
		end:;
	}
	return 0;
}
int main(int argc, char *argv[])
{
	scanf("%d%d", &n, &m);
	FOR(i,1,n)edge[i].clear();
	REP(i,m)
	{
		scanf("%d%d%d", &a, &b, &c);
		edge[a].push_back(b);
		edge[a].push_back(c);
		edge[b].push_back(a);
		edge[b].push_back(c);
		edge[c].push_back(a);
		edge[c].push_back(b);
	}
	dfs(1);
	return 0;
}


/*************************************************************
 * Filename: B_CC
 * Author: Pira
 * Date: 2013-10-15 20:19:05
 **************************************************************/
/** head files*/
/*#pragma comment(linker,"/STACK:102400000,102400000")*/
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;

/** some operate*/
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,l,h) for(int i=(l);i<=(h);++i)
#define DWN(i,h,l) for(int i=(h);i>=(l);--i)
#define foreach(e,x) for(__typeof(x.begin()) e=x.begin();e!=x.end();++e)
#define CLR(arr) memset(arr,0,sizeof(arr))

/** some const*/
#define N 200010
#define PI acos(-1.0)
#define oo 1000000000
#define loo 1000000000000000000LL
/** some alias*/
typedef long long ll;
typedef double db;

int dx[]={0,-1,0,1};
int dy[]={1,0,-1,0};
/** Global variables*/
vector< int> edge[N];
int ok[N][3], out[N];
int main(int argc, char *argv[])
{
	CLR(ok);
	int n, m, a, b, c;
	scanf("%d%d", &n, &m);
	FOR(i,1,n)edge[i].clear();
	REP(i,m)
	{
		scanf("%d%d%d", &a, &b, &c);
		edge[a].push_back(b);
		edge[a].push_back(c);
		edge[b].push_back(a);
		edge[b].push_back(c);
		edge[c].push_back(a);
		edge[c].push_back(b);
	}
	FOR(i,1,n)
		REP(j,3)
			if( !ok[i][j] )
			{
				out[i] = j + 1;
				REP(k,(int)edge[i].size())
					ok[ edge[i][k] ][j] = 1;
				break;
			}
	FOR(i,1,n)
		printf("%d%c", out[i],i<n?' ':'\n');
	return 0;
}


#include<cstdio>
#define mm 1111111
#define mn 1111111
int U[mm],D[mm],L[mm],R[mm],C[mm],id[mm];
int H[mn],S[mn],Q[mn],P[mn],X[mn];
bool p[mn];
int n,m,size;
void prepare(int r,int c)
{
    for(int i=0;i<=c;++i)
    {
        S[i]=0;
        U[i]=D[i]=i;
        L[i+1]=i;
        R[i]=i+1;
    }
    R[size=c]=0;
    while(r)H[r--]=-1;
}
void remove(int c)
{
    L[R[c]]=L[c],R[L[c]]=R[c];
    for(int i=D[c];i!=c;i=D[i])
        for(int j=R[i];j!=i;j=R[j])
            U[D[j]]=U[j],D[U[j]]=D[j],--S[C[j]];
}
void resume(int c)
{
    L[R[c]]=R[L[c]]=c;
    for(int i=U[c];i!=c;i=U[i])
        for(int j=L[i];j!=i;j=L[j])
            ++S[C[U[D[j]]=D[U[j]]=j]];
}
bool Dance(int k)
{
    if(k>=n)
    {
        for(int i=0;i<n;++i)X[ (id[Q[i]]-1)/3 ] = 1 + (id[Q[i]]-1)%3;
        for(int i=0;i<n;++i)printf("%d%c", X[i], i<n-1?' ':'\n');
        return 1;
    }
    if(!R[0])return 0;
    int i,j,c,tmp=mm;
    for(i=R[0];i;i=R[i])
        if(i<=n)
        {
            if(S[i]<tmp)tmp=S[c=i];
        }else break;
    remove(c);
    for(i=D[c];i!=c;i=D[i])
    {
        Q[k]=i;
        for(j=R[i];j!=i;j=R[j])remove(C[j]);
        if(Dance(k+1))return 1;
        for(j=L[i];j!=i;j=L[j])resume(C[j]);
    }
    resume(c);
    return 0;
}
void Link(int r,int c)
{
    ++S[C[++size]=c];
    id[size]=r;
    D[size]=D[c];
    U[D[c]]=size;
    U[size]=c;
    D[c]=size;
    if(H[r]<0)H[r]=L[size]=R[size]=size;
    else
    {
        R[size]=R[H[r]];
        L[R[H[r]]]=size;
        L[size]=H[r];
        R[H[r]]=size;
    }
}
int main()
{
	scanf("%d%d", &n, &m);
	prepare(n*3, n + m*3);
	int a;
	for(int i =0; i<m; i++)
	{
		for(int j = 0; j<3; j++)
		{
			scanf("%d", &a);
			for(int k = 1; k<4; k++)
			{
				Link( (a-1)*3 + k, n + i*3 + k);
				Link( (a-1)*3 + k, a);
			}
		}
	}
    Dance(0);
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int  d[100010],son[100010][3],pre[100010];  bool used[100010];
void  dfs(int k,int h)
{
      d[k]=h;
      int p=d[pre[k]];
      for (int i=1; i<=3; i++)
      if (i!=d[k] && i!=p)  {
                  for (int j=1; j<=son[k][0]; j++)
                   dfs (son[k][j],i);
                  }
}

int main()
{
 //   freopen("input.txt","r",stdin);
 //   freopen("output.txt","w",stdout);

    int n,m,a,b,c;  int start[10000];
    cin>>n>>m;   start[0]=0;
    memset(used,false,sizeof(used));

    for (int i=1; i<=m; i++)
    {
        cin>>a>>b>>c;
        if (used[b]) { swap(a,b); }
        else if (used[c]) { swap(a,c); }
        else if (!used[a]) { used[a]=1; pre[a]=0;
                start[0]++; start[start[0]]=a;   }
        pre[b]=a; if (son[a][0]==0) { son[a][1]=b; son[a][0]++; }
                     else { son[a][2]=b; son[a][0]++; }
        pre[c]=b; son[b][1]=c; son[b][0]++; used[b]=true;
        used[c]=true;
    }

    memset(used,false,sizeof(used));
    for (int i=1; i<=start[0]; i++)
          dfs(start[i], 1);
    for (int i=1; i<=n; i++) cout<<d[i]<<" ";

   // system("pause");
   return 0;
    }


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int  d[100010],son[100010][100],pre[100010];  bool used[100010];
void  dfs(int k,int h)
{
      d[k]=h;
      int p=d[pre[k]];
      for (int i=1; i<=3; i++)
      if (i!=d[k] && i!=p)  {
                  for (int j=1; j<=son[k][0]; j++)
                   dfs (son[k][j],i);
                  }
}

int main()
{
 //   freopen("input.txt","r",stdin);
 //   freopen("output.txt","w",stdout);

    int n,m,a,b,c;  int start[100010];
    cin>>n>>m;   start[0]=0;
    memset(used,false,sizeof(used));
    d[0]=0;
    memset(son,0,sizeof(son));
    for (int i=1; i<=m; i++)
    {
        cin>>a>>b>>c;
        if (used[b]) { swap(a,b); }
        else if (used[c]) { swap(a,c); }
        else if (!used[a]) { used[a]=1; pre[a]=0;
                start[0]++; start[start[0]]=a;   }
        pre[b]=a;
             son[a][0]++; son[a][son[a][0]]=b;
        pre[c]=b;   son[b][0]++;
        son[b][son[b][0]]=c;  used[b]=true;
        used[c]=true;
    }

    memset(used,false,sizeof(used));
    for (int i=1; i<=start[0]; i++)
          dfs(start[i], 1);
    for (int i=1; i<=n; i++) cout<<d[i]<<" ";

   // system("pause");
   return 0;
    }


#include <iostream>
#include <stdio.h>
using namespace std;

int  d[100010],son[100010][3],pre[100010];  bool used[100010];
void  dfs(int k,int h)
{
      d[k]=h;
      int p=d[pre[k]];
      for (int i=1; i<=3; i++)
      if (i!=d[k] && i!=p)  {
                  for (int j=1; j<=son[k][0]; j++)
                   dfs (son[k][j],i);
                  }
}

int main()
{
 //   freopen("input.txt","r",stdin);
 //   freopen("output.txt","w",stdout);

    int n,m,a,b,c;  int start[10000];
    cin>>n>>m;   start[0]=0;
    memset(used,false,sizeof(used));

    for (int i=1; i<=m; i++)
    {
        cin>>a>>b>>c;
        if (used[b]) { swap(a,b); }
        else if (used[c]) { swap(a,c); }
        else if (!used[a]) { used[a]=1; pre[a]=0;
                start[0]++; start[start[0]]=a;   }
        pre[b]=a; if (son[a][0]==0) { son[a][1]=b; son[a][0]++; }
                     else { son[a][2]=b; son[a][0]++; }
        pre[c]=b; son[b][1]=c; son[b][0]++; used[b]=true;
        used[c]=true;
    }

    memset(used,false,sizeof(used));
    for (int i=1; i<=start[0]; i++)
          dfs(start[i], 1);
    for (int i=1; i<=n; i++) cout<<d[i]<<" ";

    system("pause"); return 0;
    }


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int  d[100010],son[100010][3],pre[100010];  bool used[100010];
void  dfs(int k,int h)
{
      d[k]=h;
      int p=d[pre[k]];
      for (int i=1; i<=3; i++)
      if (i!=d[k] && i!=p)  {
                  for (int j=1; j<=son[k][0]; j++)
                   dfs (son[k][j],i);
                  }
}

int main()
{
 //   freopen("input.txt","r",stdin);
 //   freopen("output.txt","w",stdout);

    int n,m,a,b,c;  int start[10000];
    cin>>n>>m;   start[0]=0;
    memset(used,false,sizeof(used));

    for (int i=1; i<=m; i++)
    {
        cin>>a>>b>>c;
        if (used[b]) { swap(a,b); }
        else if (used[c]) { swap(a,c); }
        else if (!used[a]) { used[a]=1; pre[a]=0;
                start[0]++; start[start[0]]=a;   }
        pre[b]=a; if (son[a][0]==0) { son[a][1]=b; son[a][0]++; }
                     else { son[a][2]=b; son[a][0]++; }
        pre[c]=b; son[b][1]=c; son[b][0]++; used[b]=true;
        used[c]=true;
    }

    memset(used,false,sizeof(used));
    for (int i=1; i<=start[0]; i++)
          dfs(start[i], 1);
    for (int i=1; i<=n; i++) cout<<d[i]<<" ";

   // system("pause");
   return 0;
    }


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int  d[100010],son[100010][3],pre[100010];  bool used[100010];
void  dfs(int k,int h)
{
      d[k]=h;
      int p=d[pre[k]];
      for (int i=1; i<=3; i++)
      if (i!=d[k] && i!=p)  {
                  for (int j=1; j<=son[k][0]; j++)
                   dfs (son[k][j],i);
                  }
}

int main()
{
 //   freopen("input.txt","r",stdin);
 //   freopen("output.txt","w",stdout);

    int n,m,a,b,c;  int start[100000];
    cin>>n>>m;   start[0]=0;
    memset(used,false,sizeof(used));

    for (int i=1; i<=m; i++)
    {
        cin>>a>>b>>c;
        if (used[b]) { swap(a,b); }
        else if (used[c]) { swap(a,c); }
        else if (!used[a]) { used[a]=1; pre[a]=0;
                start[0]++; start[start[0]]=a;   }
        pre[b]=a; if (son[a][0]==0) { son[a][1]=b; son[a][0]++; }
                     else { son[a][2]=b; son[a][0]++; }
        pre[c]=b; son[b][1]=c; son[b][0]++; used[b]=true;
        used[c]=true;
    }

    memset(used,false,sizeof(used));
    for (int i=1; i<=start[0]; i++)
          dfs(start[i], 1);
    for (int i=1; i<=n; i++) cout<<d[i]<<" ";

   // system("pause");
   return 0;
    }


#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<vector>
#include<cstring>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define T 1001
using namespace std;
typedef unsigned long long int ll;
long n,m;
int a[100001];
void Init(){
    memset(a,0,sizeof(a));
    cin>>n>>m;
    long x,y,z;
    scanf("%ld %ld %ld",&x,&y,&z);
    a[x] = 1;a[y] = 2;a[z] =3;
    For(i,2,m){
        scanf("%ld %ld %ld",&x,&y,&z);
        if(a[x]!=0){
            a[y] = (a[x]+1)%3;
            a[z] = (a[y]+1)%3;
        }
        else if(a[y]!=0){
            a[z] = (a[y]+1)%3;
            a[z] = (a[z]+1)%3;
        }
        else if(a[z]!=0){
            a[x] = (a[z]+1)%3;
            a[y] = (a[x]+1)%3;
        }else{
            a[x] = 1;a[y] = 2;a[z] =3;
        }
    }
    For(i,1,n-1)
    if(a[i]!=0)
    printf("%d ",a[i]);
    else printf("3 ");
    if(a[n]!=0)printf("%d\n",a[n]);
    else printf("3\n");
}
int main(){
    Init();
}


#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<vector>
#include<cstring>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define T 1001
using namespace std;
typedef unsigned long long int ll;
long n,m;
int a[100001];
void Init(){
    memset(a,0,sizeof(a));
    cin>>n>>m;
    long x,y,z;
    scanf("%ld %ld %ld",&x,&y,&z);
    a[x] = 1;a[y] = 2;a[z] =3;
    For(i,2,m){
        scanf("%ld %ld %ld",&x,&y,&z);
        if(a[x]!=0){
            a[y] = (a[x]+1)%3;
            a[z] = (a[y]+1)%3;
        }
        else if(a[y]!=0){
            a[z] = (a[y]+1)%3;
            a[z] = (a[z]+1)%3;
        }
        else if(a[z]!=0){
            a[x] = (a[z]+1)%3;
            a[y] = (a[x]+1)%3;
        }
    }
    For(i,1,n-1)
    if(a[i]!=0)
    printf("%d ",a[i]);
    else printf("3 ");
    if(a[n]!=0)printf("%d\n",a[n]);
    else printf("3\n");
}
int main(){
    Init();
}


#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<vector>
#include<cstring>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define T 1001
using namespace std;
typedef unsigned long long int ll;
long n,m;
int a[100001];
void Init(){
	memset(a,0,sizeof(a));
	cin>>n>>m;
	long x,y,z;
	For(i,1,m){
		scanf("%ld %ld %ld",&x,&y,&z);
		if(a[x]!=0){
			a[y] = (a[x]+1)%3; if(a[y]==0) a[y] = 3;
			a[z] = (a[y]+1)%3; if(a[z]==0) a[y] = 3;
		}
		else if(a[y]!=0){
			a[z] = (a[y]+1)%3; if(a[z]==0) a[y] = 3;
			a[x] = (a[z]+1)%3; if(a[x]==0) a[y] = 3;
		}
		else if(a[z]!=0){
			a[x] = (a[z]+1)%3; if(a[x]==0) a[y] = 3;
			a[y] = (a[x]+1)%3; if(a[y]==0) a[y] = 3;
		}else{
			a[x] = 1;a[y] = 2;a[z] =3;
		}
	}
	For(i,1,n-1)
	printf("%d ",a[i]);
	printf("%d\n",a[n]);
}
int main(){
	Init();
}


#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<vector>
#include<cstring>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define T 1001
using namespace std;
typedef unsigned long long int ll;
long n,m;
int a[100001];
void Init(){
    memset(a,0,sizeof(a));
    cin>>n>>m;
    long x,y,z;
    For(i,1,m){
        scanf("%ld %ld %ld",&x,&y,&z);
        if(a[x]!=0){
            a[y] = (a[x]+1)%3;
            a[z] = (a[y]+1)%3;
        }
        else if(a[y]!=0){
            a[z] = (a[y]+1)%3;
            a[x] = (a[z]+1)%3;
        }
        else if(a[z]!=0){
            a[x] = (a[z]+1)%3;
            a[y] = (a[x]+1)%3;
        }else{
            a[x] = 1;a[y] = 2;a[z] =3;
        }
    }
    For(i,1,n-1)
    if(a[i]!=0)
    printf("%d ",a[i]);
    else printf("3 ");
    if(a[n]!=0)printf("%d\n",a[n]);
    else printf("3\n");
}
int main(){
    Init();
}


#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<vector>
#include<cstring>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define T 1001
using namespace std;
typedef unsigned long long int ll;
long n,m;
int a[100001];
void Init(){
    memset(a,0,sizeof(a));
    cin>>n>>m;
    long x,y,z;
    For(i,1,m){
        scanf("%ld %ld %ld",&x,&y,&z);
        if(a[x]!=0){
            a[y] = (a[x]+1)%3; if(a[y]==0) a[y] = 3;
            a[z] = (a[y]+1)%3; if(a[z]==0) a[z] = 3;
        }
        else if(a[y]!=0){
            a[z] = (a[y]+1)%3; if(a[z]==0) a[z] = 3;
            a[x] = (a[z]+1)%3; if(a[x]==0) a[x] = 3;
        }
        else if(a[z]!=0){
            a[x] = (a[z]+1)%3; if(a[x]==0) a[x] = 3;
            a[y] = (a[x]+1)%3; if(a[y]==0) a[y] = 3;
        }else{
            a[x] = 1;a[y] = 2;a[z] =3;
        }
    }
    For(i,1,n-1)
    printf("%d ",a[i]);
    printf("%d\n",a[n]);
}
int main(){
    Init();
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define maxn 100010
using namespace std;
int n,m,col[maxn];
void Paint(int a,int b,int c)
{
    if(col[a]==1)
        col[b]=2,col[c]=3;
    else if(col[a]==2)
        col[b]=1,col[c]=3;
    else
        col[b]=1,col[c]=2;
}
void read()
{
    scanf("%d %d",&n,&m);
    for(int i=1,a,b,c;i<=m;++i)
    {
        scanf("%d %d %d",&a,&b,&c);
        if(col[a])
            Paint(a,b,c);
        else if(col[b])
            Paint(b,a,c);
        else if(col[c])
            Paint(c,a,b);
        else
            col[a]=1,col[b]=2,col[c]=3;
    }
}
void print()
{
    for(int i=1;i<=n;++i)
        printf("%d%c",col[i],i<n?' ':'\n');
}
int main()
{
    read();
    print();
    return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int n,m,i,j,nxt,band;
    cin>>n>>m;
    int arr[m][3];
    for(i=0;i<m;i++)
    {
         for(j=0;j<3;j++)
         {
              cin>>arr[i][j];
         }
    }
    int dancers[n],color[3];
    memset(dancers,0,sizeof(dancers));
    for(i=0;i<m;i++)
    {
                    //cout<<i<<endl;
         color[0]=0;color[1]=0;color[2]=0;
         for(j=0;j<3;j++)
         {
               if(dancers[arr[i][j]-1]!=0)
               {
                   color[j]=dancers[arr[i][j]-1];
                   band=color[j];
               }
         }
         nxt=1;
         for(j=0;j<3;j++)
         {
            if(color[j]==nxt)
            {
               nxt++;
            }
            else if(color[j]==0)
            {
                if(band==nxt)
                nxt++;
                dancers[arr[i][j]-1]=nxt;
                nxt++;
            }
         }
         //cout<<color[0]<<" "<<color[1]<<" "<<color[2]<<endl;
    }
    for(i=0;i<n;i++)
    cout<<dancers[i]<<" ";
    cout<<endl;
   // system("pause");
}


#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int n,m,i,j,nxt;
    cin>>n>>m;
    int arr[m][3];
    for(i=0;i<m;i++)
    {
         for(j=0;j<3;j++)
         {
              cin>>arr[i][j];
         }
    }
    int dancers[n],color[3];
    memset(dancers,0,sizeof(dancers));
    for(i=0;i<m;i++)
    {
                    //cout<<i<<endl;
         color[0]=0;color[1]=0;color[2]=0;
         for(j=0;j<3;j++)
         {
               if(dancers[arr[i][j]-1]!=0)
               {
                   color[j]=dancers[arr[i][j]-1];
                   //cout<<color[j]<<endl;
               }
         }
         nxt=1;
         for(j=0;j<3;j++)
         {
            if(color[j]==nxt)
            {
               nxt++;
            }
            else
            {
                dancers[arr[i][j]-1]=nxt;
                nxt++;
            }
         }
        // cout<<color[0]<<" "<<color[1]<<" "<<color[2]<<endl;
    }
    for(i=0;i<n;i++)
    cout<<dancers[i]<<" ";
    cout<<endl;
    //system("pause");
}


#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int n,m,i,j,nxt,band;
    cin>>n>>m;
    int arr[m][3];
    for(i=0;i<m;i++)
    {
         for(j=0;j<3;j++)
         {
              cin>>arr[i][j];
         }
    }
    int dancers[n],color[3];
    memset(dancers,0,sizeof(dancers));
    for(i=0;i<m;i++)
    {
                    //cout<<i<<endl;
         color[0]=0;color[1]=0;color[2]=0;
         for(j=0;j<3;j++)
         {
               if(dancers[arr[i][j]-1]!=0)
               {
                   color[j]=dancers[arr[i][j]-1];
                   //cout<<color[j]<<endl;
               }
         }
         nxt=1;
         for(j=0;j<3;j++)
         {
            if(color[j]==nxt)
            {
               nxt++;
            }
            else if(color[j]==0)
            {
                if(band==nxt)
                nxt++;
                dancers[arr[i][j]-1]=nxt;
                nxt++;
            }
            else
            {
                 band=color[j];
            }
         }
         //cout<<color[0]<<" "<<color[1]<<" "<<color[2]<<endl;
    }
    for(i=0;i<n;i++)
    cout<<dancers[i]<<" ";
    cout<<endl;
    //system("pause");
}


#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int n,m,i,j,nxt,band;
    cin>>n>>m;
    int arr[m][3];
    for(i=0;i<m;i++)
    {
         for(j=0;j<3;j++)
         {
              cin>>arr[i][j];
         }
    }
    int dancers[n],color[3];
    memset(dancers,0,sizeof(dancers));
    for(i=0;i<m;i++)
    {
                    //cout<<i<<endl;
         color[0]=0;color[1]=0;color[2]=0;      band=0;
         for(j=0;j<3;j++)
         {
               if(dancers[arr[i][j]-1]!=0)
               {
                   color[j]=dancers[arr[i][j]-1];
                   band=color[j];
               }
         }
         nxt=1;
         for(j=0;j<3;j++)
         {
            if(color[j]==nxt)
            {
               nxt++;
            }
            else if(color[j]==0)
            {
                if(band==nxt)
                nxt++;
                dancers[arr[i][j]-1]=nxt;
                nxt++;
            }
         }
         //cout<<color[0]<<" "<<color[1]<<" "<<color[2]<<endl;
    }
    for(i=0;i<n;i++)
    cout<<dancers[i]<<" ";
    cout<<endl;
   // system("pause");
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define L(t) t<<1
#define R(t) t<<1|1
typedef long long ll;
const int maxn=300005;
int color[maxn];
int node[maxn][3];
bool dfs(int m)
{
    if(!m)
        return true;
    int c[3];
    for(int i=0;i<3;i++)
        c[i]=color[node[m][i]];
    for(int i=0;i<3;i++)
    {
        bool flag=1;
        for(int j=0;j<3;j++)
        {
            if(color[node[m][j]]==0)
                color[node[m][j]]=(i+j)%3+1;
            else if(color[node[m][j]]!=((i+j)%3+1))
            {
                flag=0;
                break;
            }
        }
        if(flag)
            if(dfs(m-1))
            return true;
        for(int j=0;j<3;j++)
            color[node[m][j]]=c[j];
    }
}
int main()
{
//    freopen("in.txt","r",stdin);
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        for(int j=0;j<3;j++)
            scanf("%d",&node[i][j]);
    }
    dfs(m);
    for(int i=1;i<=n;i++)
    {
        if(i!=1)
        printf(" ");
        printf("%d",color[i]);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define L(t) t<<1
#define R(t) t<<1|1
typedef long long ll;
const int maxn=300005;
int color[maxn];
int node[maxn][3];
int n,m;
void dfs(int deep)
{
    if(deep==m)
        return;
    int c=0;
    for(int i=0;i<3;i++)
        if(color[node[deep][i]])
        {
            c=color[node[deep][i]];
            break;
        }
    if(!c)
        for(int i=0;i<3;i++)
            color[node[deep][i]]=i+1;
    else
    {
        c=(c+2)%3;
         for(int i=0;i<3;i++)
            if(color[node[deep][i]]==0)
                color[node[deep][i]]=(++c)%3+1;
    }
    dfs(deep+1);
}
int main()
{
 //   freopen("in.txt","r",stdin);

    scanf("%d%d",&n,&m);
//    cout<<n<<" "<<m<<endl;
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<3;j++)
            scanf("%d",&node[i][j]);
    }
    dfs(0);
    for(int i=1;i<=n;i++)
    {
        if(i!=1)
        printf(" ");
        printf("%d",color[i]);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define L(t) t<<1
#define R(t) t<<1|1
typedef long long ll;
const int maxn=100005;
int color[maxn];
int node[maxn][3];
bool dfs(int m)
{
    if(!m)
        return true;
    bool c[3];
    for(int i=1;i<=3;i++)
    {
        bool flag=1;
        for(int j=0;j<3;j++)
        {
            c[j]=0;
            if(color[node[m][j]]==0)
            {
                color[node[m][j]]=(i+j)%3+1;
            }
            else if(color[node[m][j]]!=((i+j)%3+1))
            {
                c[j]=1;
                flag=0;
                break;
            }
        }
        if(flag)
            if(dfs(m-1))
            return true;
        for(int j=0;j<3;j++)
        {
            if(!c[j])
                color[node[m][j]]=0;
        }
    }
}
int main()
{
//    freopen("in.txt","r",stdin);
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        for(int j=0;j<3;j++)
            scanf("%d",&node[i][j]);
    }
    dfs(m);
    for(int i=1;i<=n;i++)
    {
        if(i!=1)
        printf(" ");
        printf("%d",color[i]);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define L(t) t<<1
#define R(t) t<<1|1
typedef long long ll;
const int maxn=300005;
int color[maxn];
int node[maxn][3];
bool dfs(int m)
{
    if(!m)
        return true;
    int c[3];
    for(int i=0;i<3;i++)
        c[i]=color[node[m][i]];
    for(int i=1;i<=3;i++)
    {
        bool flag=1;
        for(int j=0;j<3;j++)
        {
            if(color[node[m][j]]==0)
                color[node[m][j]]=(i+j)%3+1;
            else if(color[node[m][j]]!=((i+j)%3+1))
            {
                flag=0;
                break;
            }
        }
        if(flag)
            if(dfs(m-1))
            return true;
        for(int j=0;j<3;j++)
            color[node[m][j]]=c[j];
    }
}
int main()
{
//    freopen("in.txt","r",stdin);
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        for(int j=0;j<3;j++)
            scanf("%d",&node[i][j]);
    }
    dfs(m);
    for(int i=1;i<=n;i++)
    {
        if(i!=1)
        printf(" ");
        printf("%d",color[i]);
    }
    return 0;
}


/*
 * main.cpp
 *
 *  Created on: 2013-10-15
 *      Author: fangyu
 */
#include <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")

#define FOR(i,a) for((i)=0;i<(a);(i)++)
#define MEM(a) (memset((a),0,sizeof(a)))
#define LL __int64

const int N=100010;
const int M=32010;
const int MOD=1000000007ll;
const int INF=0x7fffffff;
const int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
const double eps=1e-7;
const double PI=acos(-1.0);

inline int sign(double x){return (x>eps)-(x<-eps);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
/*************************/
int n,m,pi[N];
void work(int a,int b,int c)
{
	if(pi[a]&&pi[b]&&pi[c]) return;
	if(pi[a]&&pi[b])
	{
		pi[c]=1^2^3^pi[a]^pi[b];
		return;
	}
	if(pi[a]&&pi[c])
	{
		pi[b]=1^2^3^pi[a]^pi[c];
		return;
	}
	if(pi[a]==1) pi[b]=2,pi[c]=3;
	else if(pi[a]=2) pi[b]=1,pi[c]=3;
	else pi[b]=1,pi[c]=2;
}
int main()
{
	/*
#ifndef ONLINE_JUDGE
	freopen("testin.txt","r",stdin);
	//freopen("testout.txt","w",stdout);
#endif
	 */
	int a,b,c;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		memset(pi,0,sizeof(pi));
		for(int i=1;i<=m;i++)
		{
			scanf("%d%d%d",&a,&b,&c);
			if(pi[a]) work(a,b,c);
			else if(pi[b]) work(b,a,c);
			else if(pi[c]) work(c,b,a);
			else pi[a]=1,pi[b]=2,pi[c]=3;
		}
		for(int i=1;i<n;i++) printf("%d ",pi[i]);
		printf("%d\n",pi[n]);
	}
	return 0;
}


/*
 * main.cpp
 *
 *  Created on: 2013-10-15
 *      Author: fangyu
 */
#include <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")

#define FOR(i,a) for((i)=0;i<(a);(i)++)
#define MEM(a) (memset((a),0,sizeof(a)))
#define LL __int64

const int N=100010;
const int M=32010;
const int MOD=1000000007ll;
const int INF=0x7fffffff;
const int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
const double eps=1e-7;
const double PI=acos(-1.0);

inline int sign(double x){return (x>eps)-(x<-eps);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
/*************************/
int n,m,pi[N];
int work(int a,int b,int c)
{
    if(pi[a]==1) pi[b]=2,pi[c]=3;
    else if(pi[a]=2) pi[b]=1,pi[c]=3;
    else pi[b]=1,pi[c]=2;
}
int main()
{
    /*
#ifndef ONLINE_JUDGE
    freopen("testin.txt","r",stdin);
    //freopen("testout.txt","w",stdout);
#endif
     */
    int a,b,c;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        memset(pi,0,sizeof(pi));
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d%d",&a,&b,&c);
            if(pi[a]) work(a,b,c);
            else if(pi[b]) work(b,a,c);
            else if(pi[c]) work(c,b,a);
            else pi[a]=1,pi[b]=2,pi[c]=3;
        }
        for(int i=1;i<n;i++) printf("%d ",pi[i]);
        printf("%d\n",pi[n]);
    }
    return 0;
}


/*
 * main.cpp
 *
 *  Created on: 2013-10-15
 *      Author: fangyu
 */
#include <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")

#define FOR(i,a) for((i)=0;i<(a);(i)++)
#define MEM(a) (memset((a),0,sizeof(a)))
#define LL __int64

const int N=100010;
const int M=32010;
const int MOD=1000000007ll;
const int INF=0x7fffffff;
const int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
const double eps=1e-7;
const double PI=acos(-1.0);

inline int sign(double x){return (x>eps)-(x<-eps);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
/*************************/
int n,m,pi[N];
void work(int a,int b,int c)
{
    if(pi[a]&&pi[b]&&pi[c]) return;
    if(pi[a]&&pi[b])
    {
        pi[c]=1^2^3^pi[a]^pi[b];
        return;
    }
    if(pi[a]&&pi[c])
    {
        pi[b]=1^2^3^pi[a]^pi[c];
        return;
    }
    if(pi[a]==1)
    {
        pi[b]=2;
        pi[c]=3;
    }
    else if(pi[a]=2)
    {
        pi[b]=1;
        pi[c]=3;
    }
    else
    {
        pi[b]=1;
        pi[c]=2;
    }
}
int main()
{
    /*
#ifndef ONLINE_JUDGE
    freopen("testin.txt","r",stdin);
    //freopen("testout.txt","w",stdout);
#endif
     */
    int a,b,c;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        memset(pi,0,sizeof(pi));
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d%d",&a,&b,&c);
            if(pi[a]) work(a,b,c);
            else if(pi[b]) work(b,a,c);
            else if(pi[c]) work(c,b,a);
            else
            {
                pi[a]=1;
                pi[b]=2;
                pi[c]=3;

            }
        }
        for(int i=1;i<n;i++) printf("%d ",pi[i]);
        printf("%d\n",pi[n]);
    }
    return 0;
}


/*
 * main.cpp
 *
 *  Created on: 2013-10-15
 *      Author: fangyu
 */
#include <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")

#define FOR(i,a) for((i)=0;i<(a);(i)++)
#define MEM(a) (memset((a),0,sizeof(a)))
#define LL __int64

const int N=100010;
const int M=32010;
const int MOD=1000000007ll;
const int INF=0x7fffffff;
const int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
const double eps=1e-7;
const double PI=acos(-1.0);

inline int sign(double x){return (x>eps)-(x<-eps);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
/*************************/
int n,m,pi[N];
void work(int a,int b,int c)
{
    if(pi[a]&&pi[b]&&pi[c]) return;
    if(pi[a]&&pi[b])
    {
        pi[c]=1^2^3^pi[a]^pi[b];
        return;
    }
    if(pi[a]&&pi[c])
    {
        pi[b]=1^2^3^pi[a]^pi[c];
        return;
    }
    if(pi[a]==1)
    {
        pi[b]=2;
        pi[c]=3;
    }
    else if(pi[a]==2)
    {
        pi[b]=1;
        pi[c]=3;
    }
    else
    {
        pi[b]=1;
        pi[c]=2;
    }
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("testin.txt","r",stdin);
    //freopen("testout.txt","w",stdout);
#endif
    int a,b,c;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        memset(pi,0,sizeof(pi));
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d%d",&a,&b,&c);
            if(pi[a]) work(a,b,c);
            else if(pi[b]) work(b,a,c);
            else if(pi[c]) work(c,b,a);
            else
            {
                pi[a]=1;
                pi[b]=2;
                pi[c]=3;

            }
        }
        for(int i=1;i<n;i++) printf("%d ",pi[i]);
        printf("%d\n",pi[n]);
    }
    return 0;
}


/*
 * main.cpp
 *
 *  Created on: 2013-10-15
 *      Author: fangyu
 */
#include <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")

#define FOR(i,a) for((i)=0;i<(a);(i)++)
#define MEM(a) (memset((a),0,sizeof(a)))
#define LL __int64

const int N=100010;
const int M=32010;
const int MOD=1000000007ll;
const int INF=0x7fffffff;
const int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
const double eps=1e-7;
const double PI=acos(-1.0);

inline int sign(double x){return (x>eps)-(x<-eps);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
/*************************/

vector<int> vec[N];
int n,m,pi[N],vis[N][3];
int main()
{
    /*
#ifndef ONLINE_JUDGE
    freopen("testin.txt","r",stdin);
    //freopen("testout.txt","w",stdout);
#endif
     */
    int a,b,c;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d%d",&a,&b,&c);
            int tmpa=Min(a,b,c);
            int tmpc=Max(a,b,c);
            int tmpb=a^b^c^tmpa^tmpc;
            vec[tmpa].push_back(tmpb);
            vec[tmpb].push_back(tmpc);
            vec[tmpa].push_back(tmpc);
        }
        memset(vis,0,sizeof(vis));
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=3;j++)
            {
                if(!vis[i][j-1])
                {
                    pi[i]=j;
                    for(int k=0;k<vec[i].size();k++) vis[vec[i][k]][j-1]=1;
                    break;
                }
            }
        }
        for(int i=1;i<n;i++) printf("%d ",pi[i]);
        printf("%d\n",pi[n]);
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<stack>
using namespace std;
vector<int>v[100010];
vector<int>v1;
int a[100010];
int check(int n)
{
    int o=0,t=0,th=0;
    for(int i=0; i<v[n].size(); i++)
    {
        if(a[v[n][i]]==1)
            o++;
        else if(a[v[n][i]]==2)
            t++;
        else if(a[v[n][i]]==3)
            th++;
    }
    if(o==0)
        return 1;
    else if(t==0)
        return 2;
    else if(th==0)
        return 3;
}

int main ()
{
    int i,j,k,l,m,n,h;
    while(~scanf("%d%d",&n,&m))
    {
        memset(a,0,sizeof(a));
        for(i=0; i<m; i++)
        {
            scanf("%d%d%d",&j,&k,&l);
            v[j].push_back(k);
            v[j].push_back(l);
            v[k].push_back(j);
            v[k].push_back(l);
            v[l].push_back(j);
            v[l].push_back(k);
            v1.push_back(j);
            v1.push_back(k);
            v1.push_back(l);
        }
        for(i=0; i<v1.size(); i++)
        {
            if(a[v1[i]]==0)
            {
                l=check(v1[i]);
                a[v1[i]]=l;
            }
        }
        for(i=1; i<=n; i++)
        {
            if(i!=1)
                printf(" ");
            printf("%d",a[i]);
        }
        puts("");
        i=0;
        while(v[i].size())
        {
            v[i].clear();
            i++;
        }
        v1.clear();
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<stack>
using namespace std;
vector<int>v[100010];
int a[100010];
int check(int n)
{
    int o=0,t=0,th=0;
    for(int i=0;i<v[n].size();i++)
    {
        if(a[v[n][i]]==1)
            o++;
        else if(a[v[n][i]]==2)
            t++;
        else if(a[v[n][i]]==3)
            th++;
    }
    if(o==0)
        return 1;
    else if(t==0)
        return 2;
    else if(th==0)
        return 3;
}

int main ()
{
    queue<int>q;
  int i,j,k,l,m,n,h;
  while(~scanf("%d%d",&n,&m))
  {
      memset(a,0,sizeof(a));
      for(i=0;i<m;i++)
      {
          scanf("%d%d%d",&j,&k,&l);
          v[j].push_back(k);
          v[j].push_back(l);
          v[k].push_back(j);
          v[k].push_back(l);
          v[l].push_back(j);
          v[l].push_back(k);
      }
      for(i=1;i<=n;i++)
      {
          for(j=0;j<v[i].size();j++)
          {
              k=v[i][j];
            if(a[k]==0)
              {
                  l=check(k);
              a[k]=l;
              }
          }
      }
      for(i=1;i<=n;i++)
      {
          if(i!=1)
            printf(" ");
        printf("%d",a[i]);
      }
      puts("");
       for(i=0;i<=n;i++)
            v[i].clear();
  }
  return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<stack>
using namespace std;
vector<int>v[100010];
int a[100010];
int check(int n)
{
    int o=0,t=0,th=0;
    for(int i=0; i<v[n].size(); i++)
    {
        if(a[v[n][i]]==1)
            o++;
        else if(a[v[n][i]]==2)
            t++;
        else if(a[v[n][i]]==3)
            th++;
    }
    if(o==0)
        return 1;
    else if(t==0)
        return 2;
    else if(th==0)
        return 3;
}

int main ()
{
    int i,j,k,l,m,n,h;
    while(~scanf("%d%d",&n,&m))
    {
        memset(a,0,sizeof(a));
        for(i=0; i<m; i++)
        {
            scanf("%d%d%d",&j,&k,&l);
            v[j].push_back(k);
            v[j].push_back(l);
            v[k].push_back(j);
            v[k].push_back(l);
            v[l].push_back(j);
            v[l].push_back(k);
        }
        for(i=1; i<=n; i++)
        {
            if(a[i]==0)
            {
                l=check(i);
                a[i]=l;
            }
        }
        for(i=1; i<=n; i++)
        {
            if(i!=1)
                printf(" ");
            printf("%d",a[i]);
        }
        puts("");
        for(i=0; i<=n; i++)
            v[i].clear();
    }
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <list>
#include <unordered_set>
#include <cstdio>
#include <set>
#include <cctype>
#include <stack>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <iterator>
using namespace std;
#define ull  unsigned long long
#define rtn return 0
#include <math.h>
#include <deque>
//std::vector<size_t> a(2000002, 0);
//string a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//string a = "abcdefghijklmnopqrstuvwxyz";
//string alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin.clear();
    fflush(stdin);
    int n;
    cin >> n;
    map <size_t,int> mp;
    while(n--) {
        int x;
        cin >> x;
        mp[x]++;
    }
    while(!mp.empty()) {
        if(mp.size() == 1 && mp.begin()->first != 0 && mp.begin()->second !=1) {
            cout << "YES";
            rtn;
        }
        if(mp.size() == 1 && mp.begin()->first != 0 && mp.begin()->second == 1) {
            cout << "NO";
            rtn;
        }
        auto it = mp.begin()->first;
        mp[it]--;
        if(mp[it] == 0) {
            mp.erase(it);
        }
        auto it1 = mp.rbegin()->first;
        mp[it1]--;
        if(mp[it1] == 0) {
            mp.erase(it1);
        }
        if(it1 != it) {
        mp[it1-it]++;}
    }
    cout << "YES";
    return 0;
 }


#include <bits/stdc++.h>

using namespace std;

int main()
{

  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
 /* sort(a,a+n);
  int j=0;
  int c=0;
  int f=1;
  */
 long long int b[n],c[n];

sort(a,a+n);
 b[0]=a[0];
  long long int s=0;
  for(int i=1;i<n;i++)
  {
    b[i]=b[i-1]+a[i];

}
    c[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--)
    {
        c[i]=c[i+1]+a[i];
    }
    int f=0;
   for(int i=0;i<n;i++)
   {
       if((b[i]-(b[n-1]-b[i]))>=0)
           f=1;

   }

  if(b[n-1]%2)
  cout<<"NO\n";
  else
  {
      if(f==1)
        cout<<"YES\n";
      else
        cout<<"NO\n";

  }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{

  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  sort(a,a+n);
  int j=0;
  int c=0;
  int f=1;
  for(int i=0;i<n;i++)
  {
      if(a[i]==a[j])
        c++;
      else
      {
          if(a[i]!=0)
         {
        if(c%2)
          {
              cout<<"NO\n";
               f=0;
                break;
          }

          }
      }

  }
  if(f==1)
    cout<<"YES\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{

  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
 /* sort(a,a+n);
  int j=0;
  int c=0;
  int f=1;
  */
 long long int b[n],c[n];

sort(a,a+n);
 b[0]=a[0];
  long long int s=0;
  for(int i=1;i<n;i++)
  {
    b[i]=b[i-1]+a[i];

}
    c[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--)
    {
        c[i]=c[i+1]+a[i];
    }
    int f=0;
   for(int i=0;i<n;i++)
   {
       if((b[i]-(b[n-1]-b[i]))>=0)
           f=1;

   }

  if(a[n-1]%2)
  cout<<"NO\n";
  else
  {
      if(f==1)
        cout<<"YES\n";
      else
        cout<<"NO\n";

  }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{

  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
 /* sort(a,a+n);
  int j=0;
  int c=0;
  int f=1;
  */
sort(a,a+n);
  long long int s=0;
  for(int i=1;i<n;i++)
  {
      s=a[i]-a[i-1];
      a[i]=s;
  }
    if(a[n-1]==0)
        cout<<"YES\n";
    else
        cout<<"NO\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{

  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
 /* sort(a,a+n);
  int j=0;
  int c=0;
  int f=1;
  */
sort(a,a+n);
  long long int s=0;
  for(int i=0;i<n;i++)
  {
      s=s+a[i];
  }
    if((s%2)&&((s-a[n-1])%2))
        cout<<"NO\n";
    else
        cout<<"YES\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{

  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
 /* sort(a,a+n);
  int j=0;
  int c=0;
  int f=1;
  */
 long long int b[n],c[n];

sort(a,a+n);
 b[0]=a[0];
  long long int s=0;
  for(int i=1;i<n;i++)
  {
    b[i]=b[i-1]+a[i];

}
    c[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--)
    {
        c[i]=c[i+1]+a[i];
    }
    int f=0;
   for(int i=0;i<n;i++)
   {
       if((b[i]-(b[n-1]-b[i]))>0)
           f=1;

   }

  if(a[n-1]%2)
  cout<<"NO\n";
  else
  {
      if(f==1)
        cout<<"YES\n";
      else
        cout<<"NO\n";

  }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{

  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
 /* sort(a,a+n);
  int j=0;
  int c=0;
  int f=1;
  */
 long long int b[n];

sort(a,a+n);
 b[0]=a[0];
  long long int s=0;
  for(int i=1;i<n;i++)
  {
    b[i]=b[i-1]+a[i];

}
    int f=0;
   for(int i=0;i<n-1;i++)
   {
       if((b[i]-(b[n-1]-b[i]))>=0)
           f=1;

   }

  if(b[n-1]%2)
  cout<<"NO\n";
  else
  {
      if(f==1)
        cout<<"YES\n";
      else
        cout<<"NO\n";

  }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{

  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
 /* sort(a,a+n);
  int j=0;
  int c=0;
  int f=1;
  */
  long long int s=0;
  for(int i=0;i<n;i++)
  {
      s=s+a[i];
  }
    if(s%2)
        cout<<"NO\n";
    else
        cout<<"YES\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{

  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
 /* sort(a,a+n);
  int j=0;
  int c=0;
  int f=1;
  */
 long long int b[n],c[n];

sort(a,a+n);
 b[0]=a[0];
  long long int s=0;
  for(int i=1;i<n;i++)
  {
    b[i]=b[i-1]+a[i];

}
    c[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--)
    {
        c[i]=c[i+1]+a[i];
    }
    int f=0;
   for(int i=0;i<n;i++)
   {
       if((b[i]-(c[i]-b[i]))>0)
           f=1;

   }

  if(a[n-1]%2)
  cout<<"NO\n";
  else
  {
      if(f==1)
        cout<<"YES\n";
      else
        cout<<"NO\n";

  }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ll long long
#define ull unsigned long long

ll md=(1e9)*1e9+7;
const int N=200005;
int INF=1e9+7;

char get(char x,char y)
{
    if (x=='a')
    {
        if (y=='b') return 'c';
        else return 'b';
    }
    else if (x=='b')
    {
        if (y=='a') return 'c';
        else return 'a';
    }
    else if (x=='c')
    {
        if (y=='b') return 'a';
        else return 'c';
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n,a[200005];
    ll ss=0;
    cin>>n;
    multiset<int> s;
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
        s.insert(a[i]);
        ss+=a[i];
    }
    for (int i=0;i<n-1;i++)
    {
        auto b=s.begin(),e=s.end();
        --e;
        int mn=*b,mx=*e;
        cout<<mn<<" "<<mx<<endl;
        s.erase(b);
        s.erase(e);
        mx-=mn;
        s.insert(mx);
    }
    if (a[n-2]==a[i-1]&&ss%2==0) cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ll long long
#define ull unsigned long long

ll md=(1e9)*1e9+7;
const int N=200005;
int INF=1e9+7;

char get(char x,char y)
{
    if (x=='a')
    {
        if (y=='b') return 'c';
        else return 'b';
    }
    else if (x=='b')
    {
        if (y=='a') return 'c';
        else return 'a';
    }
    else if (x=='c')
    {
        if (y=='b') return 'a';
        else return 'c';
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n,a[200005];
    cin>>n;
    ll ss=0;
    multiset<int> s;
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
        s.insert(a[i]);
        ss+=a[i];
    }
    sort(a,a+n);
    if (ss%2==1||ss-a[n-1]<a[n-1]) cout<<"NO";
    else cout<<"YES";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ll long long
#define ull unsigned long long

ll md=(1e9)*1e9+7;
const int N=200005;
int INF=1e9+7;

char get(char x,char y)
{
    if (x=='a')
    {
        if (y=='b') return 'c';
        else return 'b';
    }
    else if (x=='b')
    {
        if (y=='a') return 'c';
        else return 'a';
    }
    else if (x=='c')
    {
        if (y=='b') return 'a';
        else return 'c';
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n,a[200005];
    cin>>n;
    for (int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for (int i=0;i<n-1;i++)
    {
        a[i+1]-=a[i];
        a[i]=0;
    }
    if (a[n-1]==0) cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ll long long
#define ull unsigned long long

ll md=(1e9)*1e9+7;
const int N=200005;
int INF=1e9+7;

char get(char x,char y)
{
    if (x=='a')
    {
        if (y=='b') return 'c';
        else return 'b';
    }
    else if (x=='b')
    {
        if (y=='a') return 'c';
        else return 'a';
    }
    else if (x=='c')
    {
        if (y=='b') return 'a';
        else return 'c';
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    ll a[200005],s=0,p=0;
    cin>>n;
    int k=1;
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
        if (i)
        {
            if (a[i]!=a[i-1])
            {
                if (k%2!=0)
                {
                    cout<<"NO";
                    return 0;
                }
                else
                {
                    k=1;
                }
            }
            else k++;
        }
    }
    cout<<"YES";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ll long long
#define ull unsigned long long

ll md=(1e9)*1e9+7;
const int N=200005;
int INF=1e9+7;

char get(char x,char y)
{
    if (x=='a')
    {
        if (y=='b') return 'c';
        else return 'b';
    }
    else if (x=='b')
    {
        if (y=='a') return 'c';
        else return 'a';
    }
    else if (x=='c')
    {
        if (y=='b') return 'a';
        else return 'c';
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    ll a[200005];
    cin>>n;
    for (int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    ll s=0,k;
    vector<int> x;
    for (int i=0;i<n;i++)
    {
        if (i)
        {
            if (a[i]!=a[i-1])
            {
                if (k%2==1)
                {
                    x.pb(a[i-1]);
                    k=1;
                }
                k=1;
            }
            else k++;
        }
        else k=1;
    }
    if (k%2==1) x.pb(a[n-1]);
    if (x.size()==0)
    {
        cout<<"YES";
        return 0;
    }
    ll s1=0;
    for (int i=0;i<x.size();i++)
        s1+=x[i];
    for (int i=0;i<x.size();i++)
    {
        s+=x[i];
        s1-=x[i];
        if (s==s1)
        {
            {
                cout<<"YES";
                return 0;
            }
        }
    }
    cout<<"NO";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ll long long
#define ull unsigned long long

ll md=(1e9)*1e9+7;
const int N=200005;
int INF=1e9+7;

char get(char x,char y)
{
    if (x=='a')
    {
        if (y=='b') return 'c';
        else return 'b';
    }
    else if (x=='b')
    {
        if (y=='a') return 'c';
        else return 'a';
    }
    else if (x=='c')
    {
        if (y=='b') return 'a';
        else return 'c';
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    ll a[200005];
    cin>>n;
    for (int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    ll s=0;
    for (int i=0;i<n;i++)
    {
        if (a[i]==s) s=0;
        else s+=a[i];
    }
    cout<<(s==0?"YES":"NO");
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ll long long
#define ull unsigned long long

ll md=(1e9)*1e9+7;
const int N=200005;
int INF=1e9+7;

char get(char x,char y)
{
    if (x=='a')
    {
        if (y=='b') return 'c';
        else return 'b';
    }
    else if (x=='b')
    {
        if (y=='a') return 'c';
        else return 'a';
    }
    else if (x=='c')
    {
        if (y=='b') return 'a';
        else return 'c';
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n,a[200005];
    cin>>n;
    multiset<int> s;
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
        s.insert(a[i]);
    }
    for (int i=0;i<n-1;i++)
    {
        auto b=s.begin(),e=s.end();
        --e;
        int mn=*b,mx=*e;
        s.erase(b);
        s.erase(e);
        mx-=mn;
        s.insert(mx);
    }
    if (*s.begin()==0) cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ll long long
#define ull unsigned long long

ll md=(1e9)*1e9+7;
const int N=200005;
int INF=1e9+7;

char get(char x,char y)
{
    if (x=='a')
    {
        if (y=='b') return 'c';
        else return 'b';
    }
    else if (x=='b')
    {
        if (y=='a') return 'c';
        else return 'a';
    }
    else if (x=='c')
    {
        if (y=='b') return 'a';
        else return 'c';
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    ll a[200005],s=0,p=0;
    cin>>n;
    set<int> ss;
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
        s+=a[i];
        ss.insert(a[i]);
    }
    if (s%2==0) cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ll long long
#define ull unsigned long long

ll md=(1e9)*1e9+7;
const int N=200005;
int INF=1e9+7;

char get(char x,char y)
{
    if (x=='a')
    {
        if (y=='b') return 'c';
        else return 'b';
    }
    else if (x=='b')
    {
        if (y=='a') return 'c';
        else return 'a';
    }
    else if (x=='c')
    {
        if (y=='b') return 'a';
        else return 'c';
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    ll a[200005],s=0,p=0;
    cin>>n;
    int k=0;
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
        if (i)
        {
            if (a[i]!=a[i-1])
            {
                if (k%2!=0)
                {
                    cout<<"NO";
                    return 0;
                }
                else
                {
                    k=1;
                }
            }
            else k++;
        }
    }
    cout<<"YES";
    return 0;
}