import scala.annotation.tailrec
import scala.collection.mutable

object Main extends App {

  import scala.io.StdIn._

  solve
  @tailrec
  def solve: Unit = {
    val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
    if (n == 0) return
    val doors = Array.tabulate(m){_ ⇒
      val Array(s, t) = readLine.trim.split(' ').map(_.toInt)
      (s - 1, t - 1)
    }
    val initState = readLine.trim.split(' ').map(_.toInt).reverse.foldLeft(0){case (l, r) ⇒ l * 2 + r}
    val rooms = Array.tabulate(n){r ⇒ Room(r, Switch(readLine.trim.split(' ').let{l ⇒ l.takeRight(l.head.toInt).map(_.toInt - 1).sorted}.toList))}
    for ((s, t) ← doors){
      rooms(s).doors ::= rooms(t)
      rooms(t).doors ::= rooms(s)
    }
    val minStep = Array.tabulate(n){_ ⇒ Array.tabulate(1 << n){_ ⇒ Int.MaxValue}}
    val prevState = Array.tabulate(n){_ ⇒ Array.tabulate(1 << n){_ ⇒ ProfState(Room(0, Switch(Nil)), LightState(0))}}
    val queue = mutable.Queue[ProfState]()
    val start = ProfState(rooms(0), LightState(initState))
    queue.enqueue(start)
    minStep(start.room.number)(start.lightState.toIndex) = 0
    while (queue.nonEmpty){
      val top = queue.dequeue()
      for (next ← top.useSwitch if next.lightState.isOn(next.room.number)) {
        if (minStep(next.room.number)(next.lightState.toIndex) == Int.MaxValue) {
          minStep(next.room.number)(next.lightState.toIndex) = minStep(top.room.number)(top.lightState.toIndex) + 1
          prevState(next.room.number)(next.lightState.toIndex) = top
          queue.enqueue(next)
        }
      }
      for (next ← top.useDoor if next.lightState.isOn(next.room.number)) {
        if (minStep(next.room.number)(next.lightState.toIndex) == Int.MaxValue){
          minStep(next.room.number)(next.lightState.toIndex) = minStep(top.room.number)(top.lightState.toIndex) + 1
          prevState(next.room.number)(next.lightState.toIndex) = top
          queue.enqueue(next)
        }
      }
    }
    if (minStep(n - 1).forall(_ == Int.MaxValue)) {
      println("Help me!")
    }else if (minStep(n - 1)(LightState(0).on(n - 1).toIndex) == Int.MaxValue) {
      println("You can not switch off all lights.")
    }else {
      println(s"You can go home in ${minStep(n - 1)(LightState(0).on(n - 1).toIndex)} steps.")
      var order: List[String] = Nil
      var to = ProfState(Room(n - 1, Switch(Nil)), LightState(0).on(n - 1))
      while (to.room.number != start.room.number || to.lightState.toIndex != start.lightState.toIndex){
        val from = prevState(to.room.number)(to.lightState.toIndex)
        order ::= (if (from.room.number == to.room.number){
          from.lightState.changeTo(to.lightState) match {
            case On(r) ⇒ s"Switch on room ${r + 1}."
            case Off(r) ⇒ s"Switch off room ${r + 1}."
          }
        }else {
          s"Move to room ${to.room.number + 1}."
        })
        to = from
      }
      if (order.nonEmpty) println(order.mkString("\n"))
    }
    solve
  }

  case class Room(number: Int, switch: Switch) {
    var doors: List[Room] = Nil
  }
  case class ProfState(room: Room, lightState: LightState) {
    def useSwitch: List[ProfState] = room.switch.changeState(lightState).map(l ⇒ ProfState(room, l))
    def useDoor: List[ProfState] = room.doors.map(r ⇒ ProfState(r, lightState))
  }
  case class Switch(switch: List[Int]){
    def changeState(current: LightState): List[LightState] = switch.map{i ⇒ current.flip(i)}
  }
  sealed trait SwitchOperation
  case class On(room: Int) extends SwitchOperation
  case class Off(room: Int) extends SwitchOperation
  object LightState{
    private def toRoom(bit: Int): Int = (0 to 16).find(i ⇒ ((1 << i) & bit) != 0).get
  }
  case class LightState(toIndex: Int){
    def changeTo(that: LightState): SwitchOperation = if (toIndex > that.toIndex) Off(LightState.toRoom(toIndex ^ that.toIndex)) else On(LightState.toRoom(toIndex ^ that.toIndex))
    def isOn(room: Int): Boolean = (toIndex & (1 << room)) != 0
    def isOff(room: Int): Boolean = (toIndex & (1 << room)) == 0
    def on(room: Int): LightState = LightState(toIndex | (1 << room))
    def off(room: Int): LightState = LightState(toIndex & ~(1 << room))
    def flip(room: Int): LightState = LightState(toIndex ^ (1 << room))
  }
  implicit class Extension[T](value :T){
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
    @inline
    def also(@inline func: T ⇒ Unit): T = {func(value); value}
  }
}


Measured memory_bytes: 332484