import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.Scanner; public class Main { public static class UnionFind { int[] par; public UnionFind(int n){ this.par = new int[n]; Arrays.fill(par, -1); } public int find(int x){ if(par[x] < 0){ return x; }else{ return par[x] = find(par[x]); } } public boolean union(int x, int y){ x = find(x); y = find(y); if(x == y){ return false; } if(par[x] < par[y]){ par[x] += par[y]; par[y] = x; }else if(par[x] > par[y]){ par[y] += par[x]; par[x] = y; }else if(x < y){ par[x] += par[y]; par[y] = x; }else{ par[y] += par[x]; par[x] = y; } return true; } public int size(int x){ return -par[find(x)]; } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); final int M = sc.nextInt(); UnionFind uf = new UnionFind(N); for(int i = 0; i < M; i++){ final int A = sc.nextInt() - 1; final int B = sc.nextInt() - 1; uf.union(A, B); } for(int i = 0; i < N; i++){ System.out.println(uf.find(i) + 1); } } }