#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


enum DIR{
	Up,
	Down,
	Left,
	Right,
};

struct Info{
	Info(){
		row = col = value = 0;
		dir = Right;
	}
	Info(int arg_row,int arg_col,int arg_value,DIR arg_dir){
		row = arg_row;
		col = arg_col;
		value = arg_value;
		dir = arg_dir;
	}
	int row,col,value;
	DIR dir;
};

int main(){

	int H,W;
	scanf("%d %d",&H,&W);

	char table[H][W+1];
	for(int row = 0; row < H; row++){
		scanf("%s",table[row]);
	}

	bool check[H][W][16][4];

	for(int a = 0; a < H; a++){
		for(int b = 0; b < W; b++){
			for(int c = 0; c < 16; c++){
				for(int d = 0; d < 4; d++)check[a][b][c][d] = false;
			}
		}
	}

	Info first;
	check[0][0][0][Right] = true;

	queue<Info> Q;
	Q.push(first);

	int next_row,next_col,next_value;

	while(!Q.empty()){

		if(table[Q.front().row][Q.front().col] == '@'){
			printf("YES\n");
			return 0;
		}else{

			switch(table[Q.front().row][Q.front().col]){
			case '<':
				next_row = Q.front().row;
				if(Q.front().col == 0){
					next_col = W-1;
				}else{
					next_col = Q.front().col-1;
				}
				if(check[next_row][next_col][Q.front().value][Left] == false){
					check[next_row][next_col][Q.front().value][Left] = true;
					Q.push(Info(next_row,next_col,Q.front().value,Left));
				}
				break;
			case '>':
				next_row = Q.front().row;
				if(Q.front().col == W-1){
					next_col = 0;
				}else{
					next_col = Q.front().col+1;
				}
				if(check[next_row][next_col][Q.front().value][Right] == false){
					check[next_row][next_col][Q.front().value][Right] = true;
					Q.push(Info(next_row,next_col,Q.front().value,Right));
				}
				break;
			case '^':
				if(Q.front().row == 0){
					next_row = H-1;
				}else{
					next_row = Q.front().row-1;
				}
				next_col = Q.front().col;
				if(check[next_row][next_col][Q.front().value][Up] == false){
					check[next_row][next_col][Q.front().value][Up] = true;
					Q.push(Info(next_row,next_col,Q.front().value,Up));
				}
				break;
			case 'v':
				if(Q.front().row == H-1){
					next_row = 0;
				}else{
					next_row = Q.front().row+1;
				}
				next_col = Q.front().col;
				if(check[next_row][next_col][Q.front().value][Down] == false){
					check[next_row][next_col][Q.front().value][Down] = true;
					Q.push(Info(next_row,next_col,Q.front().value,Down));
				}
				break;
			case '_':
				if(Q.front().value == 0){
					next_row = Q.front().row;
					if(Q.front().col == W-1){
						next_col = 0;
					}else{
						next_col = Q.front().col+1;
					}
					if(check[next_row][next_col][Q.front().value][Right] == false){
						check[next_row][next_col][Q.front().value][Right] = true;
						Q.push(Info(next_row,next_col,Q.front().value,Right));
					}
				}else{
					next_row = Q.front().row;
					if(Q.front().col == 0){
						next_col = W-1;
					}else{
						next_col = Q.front().col-1;
					}
					if(check[next_row][next_col][Q.front().value][Left] == false){
						check[next_row][next_col][Q.front().value][Left] = true;
						Q.push(Info(next_row,next_col,Q.front().value,Left));
					}
				}
				break;
			case '|':
				if(Q.front().value == 0){
					if(Q.front().row == H-1){
						next_row = 0;
					}else{
						next_row = Q.front().row+1;
					}
					next_col = Q.front().col;
					if(check[next_row][next_col][Q.front().value][Down] == false){
						check[next_row][next_col][Q.front().value][Down] = true;
						Q.push(Info(next_row,next_col,Q.front().value,Down));
					}
				}else{
					if(Q.front().row == 0){
						next_row = H-1;
					}else{
						next_row = Q.front().row-1;
					}
					next_col = Q.front().col;
					if(check[next_row][next_col][Q.front().value][Up] == false){
						check[next_row][next_col][Q.front().value][Up] = true;
						Q.push(Info(next_row,next_col,Q.front().value,Up));
					}
				}
				break;
			case '?':
				next_row = Q.front().row;
				if(Q.front().col == 0){
					next_col = W-1;
				}else{
					next_col = Q.front().col-1;
				}
				if(check[next_row][next_col][Q.front().value][Left] == false){
					check[next_row][next_col][Q.front().value][Left] = true;
					Q.push(Info(next_row,next_col,Q.front().value,Left));
				}

				next_row = Q.front().row;
				if(Q.front().col == W-1){
					next_col = 0;
				}else{
					next_col = Q.front().col+1;
				}
				if(check[next_row][next_col][Q.front().value][Right] == false){
					check[next_row][next_col][Q.front().value][Right] = true;
					Q.push(Info(next_row,next_col,Q.front().value,Right));
				}

				if(Q.front().row == 0){
					next_row = H-1;
				}else{
					next_row = Q.front().row-1;
				}
				next_col = Q.front().col;
				if(check[next_row][next_col][Q.front().value][Up] == false){
					check[next_row][next_col][Q.front().value][Up] = true;
					Q.push(Info(next_row,next_col,Q.front().value,Up));
				}

				if(Q.front().row == H-1){
					next_row = 0;
				}else{
					next_row = Q.front().row+1;
				}
				next_col = Q.front().col;
				if(check[next_row][next_col][Q.front().value][Down] == false){
					check[next_row][next_col][Q.front().value][Down] = true;
					Q.push(Info(next_row,next_col,Q.front().value,Down));
				}
				break;
			case '.':
				switch(Q.front().dir){
				case Up:
					if(Q.front().row == 0){
						next_row = H-1;
					}else{
						next_row = Q.front().row-1;
					}
					next_col = Q.front().col;
					if(check[next_row][next_col][Q.front().value][Up] == false){
						check[next_row][next_col][Q.front().value][Up] = true;
						Q.push(Info(next_row,next_col,Q.front().value,Up));
					}
					break;
				case Down:
					if(Q.front().row == H-1){
						next_row = 0;
					}else{
						next_row = Q.front().row+1;
					}
					next_col = Q.front().col;
					if(check[next_row][next_col][Q.front().value][Down] == false){
						check[next_row][next_col][Q.front().value][Down] = true;
						Q.push(Info(next_row,next_col,Q.front().value,Down));
					}
					break;
				case Left:
					next_row = Q.front().row;
					if(Q.front().col == 0){
						next_col = W-1;
					}else{
						next_col = Q.front().col-1;
					}
					if(check[next_row][next_col][Q.front().value][Left] == false){
						check[next_row][next_col][Q.front().value][Left] = true;
						Q.push(Info(next_row,next_col,Q.front().value,Left));
					}
					break;
				case Right:
					next_row = Q.front().row;
					if(Q.front().col == W-1){
						next_col = 0;
					}else{
						next_col = Q.front().col+1;
					}
					if(check[next_row][next_col][Q.front().value][Right] == false){
						check[next_row][next_col][Q.front().value][Right] = true;
						Q.push(Info(next_row,next_col,Q.front().value,Right));
					}
					break;
				}
				break;
			case '+':
				if(Q.front().value == 15){
					next_value = 0;
				}else{
					next_value = Q.front().value+1;
				}
				switch(Q.front().dir){
				case Up:
					if(Q.front().row == 0){
						next_row = H-1;
					}else{
						next_row = Q.front().row-1;
					}
					next_col = Q.front().col;
					if(check[next_row][next_col][next_value][Up] == false){
						check[next_row][next_col][next_value][Up] = true;
						Q.push(Info(next_row,next_col,next_value,Up));
					}
					break;
				case Down:
					if(Q.front().row == H-1){
						next_row = 0;
					}else{
						next_row = Q.front().row+1;
					}
					next_col = Q.front().col;
					if(check[next_row][next_col][next_value][Down] == false){
						check[next_row][next_col][next_value][Down] = true;
						Q.push(Info(next_row,next_col,next_value,Down));
					}
					break;
				case Left:
					next_row = Q.front().row;
					if(Q.front().col == 0){
						next_col = W-1;
					}else{
						next_col = Q.front().col-1;
					}
					if(check[next_row][next_col][next_value][Left] == false){
						check[next_row][next_col][next_value][Left] = true;
						Q.push(Info(next_row,next_col,next_value,Left));
					}
					break;
				case Right:
					next_row = Q.front().row;
					if(Q.front().col == W-1){
						next_col = 0;
					}else{
						next_col = Q.front().col+1;
					}
					if(check[next_row][next_col][next_value][Right] == false){
						check[next_row][next_col][next_value][Right] = true;
						Q.push(Info(next_row,next_col,next_value,Right));
					}
					break;
				}
				break;
			case '-':
				if(Q.front().value == 0){
					next_value = 15;
				}else{
					next_value = Q.front().value-1;
				}
				switch(Q.front().dir){
				case Up:
					if(Q.front().row == 0){
						next_row = H-1;
					}else{
						next_row = Q.front().row-1;
					}
					next_col = Q.front().col;
					if(check[next_row][next_col][next_value][Up] == false){
						check[next_row][next_col][next_value][Up] = true;
						Q.push(Info(next_row,next_col,next_value,Up));
					}
					break;
				case Down:
					if(Q.front().row == H-1){
						next_row = 0;
					}else{
						next_row = Q.front().row+1;
					}
					next_col = Q.front().col;
					if(check[next_row][next_col][next_value][Down] == false){
						check[next_row][next_col][next_value][Down] = true;
						Q.push(Info(next_row,next_col,next_value,Down));
					}
					break;
				case Left:
					next_row = Q.front().row;
					if(Q.front().col == 0){
						next_col = W-1;
					}else{
						next_col = Q.front().col-1;
					}
					if(check[next_row][next_col][next_value][Left] == false){
						check[next_row][next_col][next_value][Left] = true;
						Q.push(Info(next_row,next_col,next_value,Left));
					}
					break;
				case Right:
					next_row = Q.front().row;
					if(Q.front().col == W-1){
						next_col = 0;
					}else{
						next_col = Q.front().col+1;
					}
					if(check[next_row][next_col][next_value][Right] == false){
						check[next_row][next_col][next_value][Right] = true;
						Q.push(Info(next_row,next_col,next_value,Right));
					}
					break;
				}
				break;
			default: //'0'-'9'
				next_value = table[Q.front().row][Q.front().col]-'0';
				switch(Q.front().dir){
				case Up:
					if(Q.front().row == 0){
						next_row = H-1;
					}else{
						next_row = Q.front().row-1;
					}
					next_col = Q.front().col;
					if(check[next_row][next_col][next_value][Up] == false){
						check[next_row][next_col][next_value][Up] = true;
						Q.push(Info(next_row,next_col,next_value,Up));
					}
					break;
				case Down:
					if(Q.front().row == H-1){
						next_row = 0;
					}else{
						next_row = Q.front().row+1;
					}
					next_col = Q.front().col;
					if(check[next_row][next_col][next_value][Down] == false){
						check[next_row][next_col][next_value][Down] = true;
						Q.push(Info(next_row,next_col,next_value,Down));
					}
					break;
				case Left:
					next_row = Q.front().row;
					if(Q.front().col == 0){
						next_col = W-1;
					}else{
						next_col = Q.front().col-1;
					}
					if(check[next_row][next_col][next_value][Left] == false){
						check[next_row][next_col][next_value][Left] = true;
						Q.push(Info(next_row,next_col,next_value,Left));
					}
					break;
				case Right:
					next_row = Q.front().row;
					if(Q.front().col == W-1){
						next_col = 0;
					}else{
						next_col = Q.front().col+1;
					}
					if(check[next_row][next_col][next_value][Right] == false){
						check[next_row][next_col][next_value][Right] = true;
						Q.push(Info(next_row,next_col,next_value,Right));
					}
					break;
				}
				break;
			}
		}

		Q.pop();
	}

	printf("NO\n");

	return 0;
}

Measured memory_bytes: 3212