using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); static int[] LList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => int.Parse(ReadLine())).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, m) = (c[0], c[1]); var tree = new List<(int to, int x)>[n]; for (var i = 0; i < n; ++i) tree[i] = new List<(int to, int x)>(); for (var i = 0; i < m; ++i) { c = NList; var y = NN; tree[c[0] - 1].Add((c[1] - 1, y)); tree[c[1] - 1].Add((c[0] - 1, y)); } var ans = Enumerable.Repeat(-1, n).ToArray(); for (var i = 0; i < n; ++i) if (ans[i] < 0) { ans[i] = 0; if (!DFS(i, -1, tree, ans)) { WriteLine(-1); return; } } WriteLine(string.Join("\n", ans)); } static bool DFS(int cur, int prev, List<(int to, int x)>[] tree, int[] ans) { foreach (var next in tree[cur]) { if (prev == next.to) continue; if (ans[next.to] < 0) { ans[next.to] = ans[cur] ^ next.x; if (!DFS(next.to, cur, tree, ans)) return false; } else if (ans[next.to] != (ans[cur] ^ next.x)) return false; } return true; } }