#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long R = 7 + 1e9, NUMTESTCASE;
const long long NN = 10 + 1e6;
const double pi = acos(-1.0);
int di[8] = {1, 0, -1, 0, 1, -1, 1, -1}, dj[8] = {0, 1, 0, -1, 1, -1, -1, 1};
int Ans[NN], n, m, Arr[NN][4];
vector<int> Pos[NN];
bool Vis[NN];
void Solve(int Start) {
  queue<int> Queue;
  Queue.push(Start);
  Vis[Start] = true;
  while (Queue.size()) {
    int k = Queue.front();
    Queue.pop();
    vector<int> Temp;
    for (int j = (1); j <= (3); ++j)
      if (Ans[Arr[k][j]] + 1) Temp.push_back(Ans[Arr[k][j]]);
    if (Temp.size() == 3) continue;
    vector<int> T;
    for (int p = (1); p <= (3); ++p) {
      bool Find = false;
      for (int u : Temp) Find |= (u == p);
      if (!Find)
        for (int j = (1); j <= (3); ++j)
          if (Ans[Arr[k][j]] == -1) {
            Ans[Arr[k][j]] = p;
            for (int v : Pos[Arr[k][j]])
              if (!Vis[v]) Queue.push(v), Vis[v] = true;
            break;
          }
    }
  }
}
int main() {
  scanf("%d%d", &m, &n);
  for (int i = (1); i <= (n); ++i)
    for (int j = (1); j <= (3); ++j) {
      scanf("%d", &Arr[i][j]);
      Pos[Arr[i][j]].push_back(i);
    }
  memset(Ans, -1, sizeof(Ans));
  for (int i = (1); i <= (n); ++i)
    if (!Vis[i]) Solve(i);
  for (int i = (1); i <= (m); ++i) printf("%d ", Ans[i]);
  return 0;
}
