import sequtils,strutils
type
    unionfindtree[I : static[int]] = array[I,int]
var N,M : int
(N, M) = stdin.readline.split.map(parseInt)
var
    num = newSeqWith(N + 1,1)
    ut : unionfindtree[10001]
    a,b : int
proc initUT[I](i : int):unionfindtree[I] =
    unionfindtree[i]
    
proc find(U : unionfindtree; a : int, b :int): bool=
    var
        s = a
        t = b
    while s != U[s]:
        s = U[s]
    while t != U[t]:
        t = U[t]
    return s == t
    
proc union(U : var  unionfindtree; a : int ; b : int)=
    if U.find(a,b):
        return
    var
        s = a
        t = b
        t2 : int
    while s != U[s]:
        s = U[s]
    while t != U[t]:
        t = U[t]
    if num[s] < num[t]:
        U[s] = t
        num[t] += num[s]
        num[s] = 0
    if num[t] < num[s]:
        U[t] = s
        num[s] += num[t]
        num[t] = 0
    if num[t] == num[s]:
        if t < s:
            (t, s) = (s, t)
        U[t] = s
        num[s] += num[t]
        num[t] = 0
proc root(U : unionfindtree, a :int):int=
    var
        s = a
    while s != U[s]:
        s = U[s]
    return s


for i in 1..N:
    ut[i] = i

for m in 1..M:
    (a, b) = stdin.readline.split.map(parseInt)
    ut.union(a,b)
for i in 1..N:
    echo ut.root(i)