import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.Queue
import scala.collection.mutable.PriorityQueue

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)


  val N, M = in.next().toInt

  val g = Array.fill[List[Int]](N+1)(Nil)

  for (_ <- 1 to N-1+M) {
    val a, b = in.next().toInt
    g(a) = b :: g(a)
  }


  //
  val dp2 = new Array[Int](N+1)
  for (i <- 1 to N) {
    for(e <- g(i)) {
      dp2(e) += 1
    }
  }

  var root = -1
  for (i <- 1 to N) {
    if(dp2(i) == 0)
      root = i
  }


  val dp = Array.fill[(Int, Int)](N+1)((0, 0)) // cost, oya
  val q = new PriorityQueue[(Int, Int, Int)]() // (node, cost)

  q.enqueue((-1, root, root))

  while(!q.isEmpty) {
    val (_cost, node, paren) = q.dequeue
    val cost = -cost
    if(dp(node)._1 < cost) {
      dp(node) = (cost, paren)
      for(e <- g(node)) {
        q.enqueue((-(cost+1), node))
      }
    }
  }

  for (i <- 1 to N) {
    if(i == root)
      println(0)
    else
      println(dp(i)._2)
  }
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}

