(n,m),*ab=$<.map{|s|s.split.map &:to_i}

par=$par=[nil]*(n+1)

def anc(a,b)
  p=$par[b]
  p=$par[p] while p&&a!=p
  p==a
end

que=ab
until que.empty?
  a,b=que.shift
  if par[b]==nil
    par[b]=a
  elsif anc(par[b],a)
    par[b]=a
  elsif anc(a,b)
    #
  else
    que.push([a,b])
  end
end

par[1,n].map{|e|puts(e || 0)}
