#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int N, K;

bool cmp(const pii &a, const pii &b){
    if(a.first == b.first) return a.second < b.second;
    return a.first < b.first;
}

struct Edge {
    int to, cost;
    Edge(int to, int cost): to(to), cost(cost) {}
};

typedef vector<vector<Edge>> AdjList;
AdjList graph;

const int INF = 100000000;

vi dist;
int d[110][110];

bool bellman_ford(int n, int s) { // nは頂点数、sは開始頂点
    dist = vector<int>(n, INF);
    dist[s] = 0; // 開始点の距離は0
    for (int i = 0; i < n; i++) {
        for (int v = 0; v < n; v++) {
            for (int u = 0; u < n; u++) {
                if (dist[v] != INF && dist[u] > dist[v] + d[v][u]) {
                    dist[u] = dist[v] + d[v][u];
                    if (i == n - 1) return true; // n回目にも更新があるなら負の閉路が存在
                }
            }
        }
    }
    return false;
}

vector<string> field;
bool f = false;
int R, C;
bool state[25][25][20][4];
map<char, int> mp;
void dfs(int y, int x, int mem, char dir, int cnt){
    if(f) return;

    if(state[y][x][mem][mp[dir]] == true) return;
    state[y][x][mem][mp[dir]] = true;

    if(field[y][x] == '@'){
        f = true;
        return;
    }
    if(field[y][x] >= '0' && field[y][x] <= '9'){
        if(dir == 'N') {
            dfs((y-1+R)%R, x, field[y][x] - '0', 'N', cnt+1);
        }else if(dir == 'S'){
            dfs((y+1+R)%R, x, field[y][x] - '0', 'S', cnt+1);
        }else if(dir == 'E'){
            dfs(y, (x+1+C)%C, field[y][x] - '0', 'E', cnt+1);
        }else {
            dfs(y, (x-1+C)%C, field[y][x] -'0', 'W', cnt+1);
        }
    }

    if(field[y][x] == '<'){
        dfs(y, (x-1+C)%C, mem, 'W', cnt+1);
    }

    if(field[y][x] == '>'){
        dfs(y, (x+1+C)%C, mem, 'E', cnt+1);
    }

    if(field[y][x]== '^'){
        dfs((y-1+R)%R, x, mem, 'N', cnt+1);
    }

    if(field[y][x] == 'v'){
        dfs((y+1+R)%R, x, mem, 'S', cnt+1);
    }

    if(field[y][x] == '_'){
        if(mem == 0){
            dfs(y, (x+1+C)%C, mem, 'E', cnt+1);
        }else{
            dfs(y, (x-1+C)%C, mem, 'W', cnt+1);
        }
    }

    if(field[y][x] == '|'){
        if(mem == 0){
            dfs((y+1+R)%R, x, mem, 'S', cnt+1);
        }else{
            dfs((y-1+R)%R, x, mem, 'N', cnt+1);
        }
    }

    if(field[y][x] == '?'){
        dfs(y, (x-1+C)%C, mem, 'W', cnt+1);
        dfs(y, (x+1+C)%C, mem, 'E', cnt+1);
        dfs((y+1+R)%R, x, mem, 'S', cnt+1);
        dfs((y-1+R)%R, x, mem, 'N', cnt+1);
    }

    if(field[y][x] == '.'){
        if(dir == 'N') {
            dfs((y-1+R)%R, x, mem, 'N', cnt+1);
        }else if(dir == 'S'){
            dfs((y+1+R)%R, x, mem, 'S', cnt+1);
        }else if(dir == 'E'){
            dfs(y, (x+1+C)%C, mem, 'E', cnt+1);
        }else {
            dfs(y, (x-1+C)%C, mem, 'W', cnt+1);
        }
    }

    if(field[y][x] == '+'){
        if(dir == 'N') {
            dfs((y-1+R)%R, x, (mem+1+16)%16, 'N', cnt+1);
        }else if(dir == 'S'){
            dfs((y+1+R)%R, x, (mem+1+16)%16, 'S', cnt+1);
        }else if(dir == 'E'){
            dfs(y, (x+1+C)%C, (mem+1+16)%16, 'E', cnt+1);
        }else {
            dfs(y, (x-1+C)%C, (mem+1+16)%16, 'W', cnt+1);
        }
    }

    if(field[y][x] == '-'){
        if(dir == 'N') {
            dfs((y-1+R)%R, x, (mem-1+16)%16, 'N', cnt+1);
        }else if(dir == 'S'){
            dfs((y+1+R)%R, x, (mem-1+16)%16, 'S', cnt+1);
        }else if(dir == 'E'){
            dfs(y, (x+1+C)%C, (mem-1+16)%16, 'E', cnt+1);
        }else {
            dfs(y, (x-1+C)%C, (mem-1+16)%16, 'W', cnt+1);
        }
    }
}
int main() {
    //cout << fixed << setprecision(15);

    cin >> R >> C;
    REP(i, R){
        string str; cin >> str;
        field.push_back(str);
    }

    bool state[25][25][20][4];
    mp['N'] = 0;
    mp['S'] = 1;
    mp['W'] = 2;
    mp['E'] = 3;
    REP(i, 25) REP(j, 25) REP(k, 20) REP(l, 4) state[i][j][k][l]=false;

    dfs(0, 0, 0, 'E', 0);

    if(f) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 4444