import java.util.Arrays; import java.util.Scanner; public class Main { final long MODULO = 1_000_000_000 + 7; void run() { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); DJSet ds = new DJSet(n); for (int i = 0; i < m; ++i) { int a = sc.nextInt(); int b = sc.nextInt(); --a; --b; ds.setUnion(a, b); } for (int i = 0; i < n; ++i) { System.out.println(ds.root(i) + 1); } } class DJSet { int n; int[] upper; public DJSet(int n_) { n = n_; upper = new int[n]; Arrays.fill(upper, -1); } boolean equiv(int x, int y) { return root(x) == root(y); } int root(int x) { return upper[x] < 0 ? x : (upper[x] = root(upper[x])); } void setUnion(int x, int y) { x = root(x); y = root(y); if (x == y) { return; } if (upper[x] < upper[y]) { int d = x; x = y; y = d; } if (upper[x] == upper[y] && x < y) { int d = x; x = y; y = d; } upper[y] += upper[x]; upper[x] = y; } } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } public static void main(String[] args) { new Main().run(); } }