#include <bits/stdc++.h>
using namespace std;
int d[100001][3];
vector<int> v[100001];
int c[100001];
set<int> cd[100001];
stack<int> q;
void add_color(int x, int cc) {
  c[x] = cc;
  for (int i = 0; i < v[x].size(); i++) {
    cd[v[x][i]].insert(cc);
    q.push(v[x][i]);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> d[i][j];
      d[i][j]--;
      if (i != 0) v[d[i][j]].push_back(i);
    }
  }
  add_color(d[0][0], 1);
  add_color(d[0][1], 2);
  add_color(d[0][2], 3);
  for (int i = 1; i < m; i++) {
    while (!q.empty()) {
      int x = q.top();
      q.pop();
      if (cd[x].size() == 2) {
        int ccc = 0;
        if (cd[x].find(1) == cd[x].end()) ccc = 1;
        if (cd[x].find(2) == cd[x].end()) ccc = 2;
        if (cd[x].find(3) == cd[x].end()) ccc = 3;
        int tan = 0;
        if (c[d[x][0]] == 0) tan = d[x][0];
        if (c[d[x][1]] == 0) tan = d[x][1];
        if (c[d[x][2]] == 0) tan = d[x][2];
        add_color(tan, ccc);
      }
      if (cd[x].size() == 1) {
        int ccc1 = 0, ccc2 = 0;
        if (cd[x].find(1) != cd[x].end()) ccc1 = 2, ccc2 = 3;
        if (cd[x].find(2) != cd[x].end()) ccc1 = 1, ccc2 = 3;
        if (cd[x].find(3) != cd[x].end()) ccc1 = 1, ccc2 = 2;
        int tan = 0;
        if (c[d[x][0]] != 0) {
          add_color(d[x][1], ccc1);
          add_color(d[x][2], ccc2);
          continue;
        }
        if (c[d[x][1]] != 0) {
          add_color(d[x][0], ccc1);
          add_color(d[x][2], ccc2);
          continue;
        }
        if (c[d[x][2]] != 0) {
          add_color(d[x][1], ccc1);
          add_color(d[x][0], ccc2);
        }
      }
    }
    if (cd[i].size() == 2) {
      int ccc = 0;
      if (cd[i].find(1) == cd[i].end()) ccc = 1;
      if (cd[i].find(2) == cd[i].end()) ccc = 2;
      if (cd[i].find(3) == cd[i].end()) ccc = 3;
      int tan = 0;
      if (c[d[i][0]] == 0) tan = d[i][0];
      if (c[d[i][1]] == 0) tan = d[i][1];
      if (c[d[i][2]] == 0) tan = d[i][2];
      add_color(tan, ccc);
    }
    if (cd[i].size() == 1) {
      int ccc1 = 0, ccc2 = 0;
      if (cd[i].find(1) != cd[i].end()) ccc1 = 2, ccc2 = 3;
      if (cd[i].find(2) != cd[i].end()) ccc1 = 1, ccc2 = 3;
      if (cd[i].find(3) != cd[i].end()) ccc1 = 1, ccc2 = 2;
      int tan = 0;
      if (c[d[i][0]] != 0) {
        add_color(d[i][1], ccc1);
        add_color(d[i][2], ccc2);
        continue;
      }
      if (c[d[i][1]] != 0) {
        add_color(d[i][0], ccc1);
        add_color(d[i][2], ccc2);
        continue;
      }
      if (c[d[i][2]] != 0) {
        add_color(d[i][1], ccc1);
        add_color(d[i][0], ccc2);
      }
    }
    if (cd[i].size() == 0) {
      add_color(d[i][0], 1);
      add_color(d[i][1], 2);
      add_color(d[i][2], 3);
    }
  }
  for (int i = 0; i < n; i++) cout << c[i] << " ";
  return 0;
}
