object Main extends App {
  val in = scala.io.Source.stdin.getLines.toSeq
  val ls = in.map(_.split(' ').map(_.toInt))
  val N = ls(0)(0)
  val input = ls.tail
  
  val nodes = (0 to N).map(e => Seq[Int]()).toArray
  input.foreach{ l =>
    val l0 = l(0)
    val l1 = l(1)
    nodes(l0) = nodes(l0) :+ l1
    nodes(l1) = nodes(l1) :+ l0
  }
  
  private def depth(i:Int, visited:Seq[Int]):Int = {
    val maxdepth = (nodes(i).map{ e =>
      val sub = if(visited.contains(e)) 0 else 1 + depth(e, (visited :+ i)) 
      if(sub>=3) return 3
      sub
    } :+ 0).max
    return maxdepth
  }
  //println(nodes.toSeq)
  //println(depth(1, Seq()))
  val all = (0 until N).map(e => depth(e, Seq()) ).max
  //println(all)
  
  if(all<3) println(-1)
  else println((1 to N).map(e => 3).mkString(" "))
}
