#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
ll n, m;
ll x[101010][4], k[101010];
ll a[101010];
struct Random {
mt19937 rd;
Random() : rd(chrono::steady_clock::now().time_since_epoch().count()){}
int randInt(int l, int r) { return uniform_int_distribution<int>(l, r)(rd); }
} rd;
int epoch = 500;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
for (int j = 0; j < 4; j++) cin >> x[i][j];
cin >> k[i];
}
while (epoch--) {
for (int i = 1; i <= n; i++) a[i] = rd.randInt(0, 3);
int cnt = 0;
for (int i = 0; i < m; i++) {
int tmp = 0;
for (int j = 0; j < 4; j++) tmp += a[x[i][j]];
if (tmp % 4 == k[i]) cnt++;
}
if (cnt >= m / 4) {
for (int i = 1; i <= n; i++) cout << a[i] << " ";
return 0;
}
}
return 0;
}