object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val Array(r, c) = readLine.trim.split(' ').map(_.toInt)
  val arg = Array.tabulate(r){_ ⇒ readLine.trim}
  val program = new Program(arg)
  val isReach = Array.tabulate(r){_ ⇒ Array.tabulate(c){_ ⇒ Array.tabulate(16){_ ⇒ Array.tabulate(4){_ ⇒ false}}}}.also{m ⇒ m(0)(0)(0)(Right.asInt) = true}
  var state = List(State(Position(0, 0), Right, 0))
  var reachToGoal = program(Position(0, 0)) == End
  while (!reachToGoal && state.nonEmpty){
    state = state.flatMap{s ⇒
      program.doStep(s)
    }.filterNot{
      case State(p@Position(x, y), direction, memory) if !isReach(y)(x)(memory)(direction.asInt) ⇒
        isReach(y)(x)(memory)(direction.asInt) = true
        if (program(p) == End)
          reachToGoal = true
        false
      case _ ⇒ true: Boolean
    }
  }
  println(
    if (reachToGoal) "YES" else "NO"
  )

  class Program(state: Array[String]) {
    private val mState = state.map{line ⇒ line.map{
      case '<' ⇒ SetToLeft
      case '>' ⇒ SetToRight
      case '^' ⇒ SetToUp
      case 'v' ⇒ SetToDown
      case '_' ⇒ Horizontal
      case '|' ⇒ Vertical
      case '?' ⇒ Random
      case '.' ⇒ DoNothing
      case '@' ⇒ End
      case h if h.isDigit ⇒ Write(h.asDigit)
      case '+' ⇒ Increment
      case '-' ⇒ Decrement
      case _ ⇒ ???
    }.toArray}
    private val mHeight = mState.length
    private val mWidth = mState.head.length
    def apply(position: Position): Token = mState(position.y)(position.x)
    def doStep(state: State): List[State] = {
      this(state.position).changeState(state).map{st ⇒ st.copy(position = st.position.move(st.direction)).let{s ⇒ s.copy(position = Position((s.position.x + mWidth) % mWidth, (s.position.y + mHeight) % mHeight))}}
    }
  }
  case class State(position: Position, direction: Direction, memory: Int)

  case class Position(x: Int, y: Int) {
    def move(direction: Direction): Position = {
      direction match {
        case Right ⇒ Position(x + 1, y)
        case Left ⇒ Position(x - 1, y)
        case Up ⇒ Position(x, y - 1)
        case Down ⇒ Position(x, y + 1)
      }
    }
  }

  sealed trait Direction {
    def asInt: Int = this match {
      case Right ⇒ 0
      case Left ⇒ 1
      case Up ⇒ 2
      case Down ⇒ 3
    }
  }
  case object Right extends Direction
  case object Left extends Direction
  case object Down extends Direction
  case object Up extends Direction

  sealed trait Token {
    def changeState(state: State): List[State]
  }
  sealed trait SetDirection extends Token {
    override def changeState(state: State): List[State] = {
      (this match {
        case SetToLeft ⇒ Left
        case SetToRight ⇒ Right
        case SetToUp ⇒ Up
        case SetToDown ⇒ Down
      }).let{dir ⇒ List(state.copy(direction = dir))}
    }
  }
  case object SetToLeft extends SetDirection
  case object SetToRight extends SetDirection
  case object SetToUp extends SetDirection
  case object SetToDown extends SetDirection
  sealed trait ChangeDirection extends Token
  case object Horizontal extends ChangeDirection {
    override def changeState(state: State): List[State]= List(if (state.memory == 0) state.copy(direction = Right) else state.copy(direction = Left))
  }
  case object Vertical extends ChangeDirection {
    override def changeState(state: State): List[State] = List(if (state.memory == 0) state.copy(direction = Down) else state.copy(direction = Up))
  }
  case object Random extends Token {
    override def changeState(state: State): List[State] = {
      List(Right, Left, Down, Up).map{dir ⇒ state.copy(direction = dir)}
    }
  }
  case object DoNothing extends Token {
    override def changeState(state: State): List[State] = List(state)
  }
  case object End extends Token {
    override def changeState(state: State): List[State] = Nil
  }
  sealed trait ChangeMemory extends Token
  case class Write(value: Int) extends ChangeMemory {
    override def changeState(state: State): List[State] = List(state.copy(memory = value))
  }
  case object Increment extends ChangeMemory {
    override def changeState(state: State): List[State] = List(state.copy(memory = (state.memory + 1) % 16))
  }
  case object Decrement extends ChangeMemory {
    override def changeState(state: State): List[State] = List(state.copy(memory = (state.memory + 15) % 16))
  }
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


Measured memory_bytes: 78380