using System; using System.IO; using System.Collections.Generic; namespace No556 { public class Program { void Solve(StreamScanner ss, StreamWriter sw) { //--------------------------------- var N = ss.Next(int.Parse); var M = ss.Next(int.Parse); var uf = new UnionFind(N + 1); for (var i = 0; i < M; i++) { var A = ss.Next(int.Parse); var B = ss.Next(int.Parse); if (uf.Root(A) > uf.Root(B)) MathX.Swap(ref A, ref B); uf.Unite(A, B); } for (var i = 1; i <= N; i++) { sw.WriteLine(uf.Root(i)); } //--------------------------------- } static void Main() { var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput())); var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false}; new Program().Solve(ss, sw); sw.Flush(); } } public static partial class MathX { public static void Swap(ref T left, ref T right) { var tmp = left; left = right; right = tmp; } } public class UnionFind { readonly int[] p; public UnionFind(int n) { p = new int[n]; for (var i = 0; i < n; i++) p[i] = -1; } public int Root(int x) { return p[x] < 0 ? x : (p[x] = Root(p[x])); } public bool IsSameSet(int x, int y) { return Root(x) == Root(y); } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) return false; if (p[x] > p[y]) { var t = x; x = y; y = t; } p[x] += p[y]; p[y] = x; return true; } public int Size(int x) { return -p[Root(x)]; } } public class StreamScanner { static readonly char[] Sep = {' '}; readonly Queue buffer = new Queue(); readonly TextReader textReader; public StreamScanner(TextReader textReader) { this.textReader = textReader; } public T Next(Func parser) { if (buffer.Count != 0) return parser(buffer.Dequeue()); var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries); foreach (var nextString in nextStrings) buffer.Enqueue(nextString); return Next(parser); } public T[] Next(Func parser, int x) { var ret = new T[x]; for (var i = 0; i < x; ++i) ret[i] = Next(parser); return ret; } public T[][] Next(Func parser, int x, int y) { var ret = new T[y][]; for (var i = 0; i < y; ++i) ret[i] = Next(parser, x); return ret; } } }