#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}

int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
string dir = ">v<^";
/*
hand:
0:正面　dx[d], dy[d]
1:斜め右前　dx[d]+dx[d+1], dy[d]+dy[d+1]
2:右 　dx[d+1], dy[d+1]
3:斜め右後ろ　dx[d+1]+dx[d+2], dy[d+1]+dy[d+2]
左折時
0 -> 2
1 -> 3
右折時
2 -> 0
3 -> 1
前進
1 -> 2
2 -> 3

*/

#define in(a,b,c,d) make_pair(pii(a,b),pii(c,d))

int n,m;

bool f(int x,int y){
    if(x < 0 || n <= x)return false;
    if(y < 0 || m <= y)return false;
    return true;
}

signed main(void) {
    cin >> n >> m;
    string tmp = "";
    rep(i,m)tmp += "#";
    vs s(n+2,tmp);
    rep(i,n) cin >> s[i+1];
    n += 2;
    m += 2;
    rep(i,n)s[i] = "#" + s[i] + "#";

    int g[55][55][4][4];
    rep(i,55)rep(j,55)rep(k,4)rep(l,4)g[i][j][k][l] = INF;
    queue<pair<pii,pii> > q;
    int sx,sy;
    rep(i,n)rep(j,m)rep(k,4)if(s[i][j] == dir[k]){
        q.push(in(i,j,k,2));
        g[i][j][k][2] = 0;
        sx = i,sy = j;
    }
    while(q.size()){
        pair<pii,pii> now = q.front();
        q.pop();
        int x = now.first.first;
        int y = now.first.second;
        int d = now.second.first;
        int h = now.second.second;
        if(s[x][y] == 'G')break;
        //cout << x << " " << y << " " << d << " " << h << " " << g[x][y][d][h] << endl;

        if(h == 1 || h == 2){//前進
            int nx = x + dx[d];
            int ny = y + dy[d];
            if(f(nx,ny) && s[nx][ny] != '#' && g[x][y][d][h]+1 < g[nx][ny][d][h+1]){
                g[nx][ny][d][h+1] = g[x][y][d][h]+1;
                q.push(in(nx,ny,d,h+1));
                //cout << " " << nx << " " << ny << " " << d << " " << h+1 << " " << g[nx][ny][d][h+1] << endl;

            }
        }
        if(h == 0 || h == 1){//左折
            if(g[x][y][d][h] < g[x][y][(d+3)%4][h+2]){
                g[x][y][(d+3)%4][h+2] = g[x][y][d][h];
                q.push(in(x,y,(d+3)%4,h+2));
                //cout << " " << x << " " << y << " " << (d+3)%4 << " " << h+2 << " " << g[x][y][(d+3)%4][h+2] << endl;

            }
        }else{//右折
            if(g[x][y][d][h] < g[x][y][(d+1)%4][h-2]){
                g[x][y][(d+1)%4][h-2] = g[x][y][d][h];
                q.push(in(x,y,(d+1)%4,h-2));
                //cout << " " << x << " " << y << " " << (d+1)%4 << " " << h-2 << " " << g[x][y][(d+1)%4][h-2] << endl;
            }
        }
        int hx = x,hy = y;
        switch (h) {
            case 1: hx += dx[(d+1)%4]; hy += dy[(d+1)%4];
            case 0: hx += dx[d]; hy += dy[d];break;
            case 3: hx += dx[(d+2)%4]; hy += dy[(d+2)%4];
            case 2: hx += dx[(d+1)%4]; hy += dy[(d+1)%4];break;
        }
        //cout << " " << hx << " " << hy << endl;
        //手の場所を変える
        int tx,ty;
        tx = x + dx[d];
        ty = y + dy[d];
        if(f(tx,ty) && s[tx][ty] == '#' && abs(hx - tx) <= 1 && abs(hy - ty) <= 1){
            if(g[x][y][d][h] < g[x][y][d][0]){
                g[x][y][d][0] = g[x][y][d][h];
                q.push(in(x,y,d,0));
                //cout << " " << x << " " << y << " " << d << " " << 0 << " " << g[x][y][d][0] << endl;

            }
        }

        tx = x + dx[d] + dx[(d+1)%4];
        ty = y + dy[d] + dy[(d+1)%4];
        if(f(tx,ty) && s[tx][ty] == '#' && abs(hx - tx) <= 1 && abs(hy - ty) <= 1){
            if(g[x][y][d][h] < g[x][y][d][1]){
                g[x][y][d][1] = g[x][y][d][h];
                q.push(in(x,y,d,1));
                //cout << " " << x << " " << y << " " << d << " " << 1 << " " << g[x][y][d][1] << endl;
            }
        }

        tx = x + dx[(d+1)%4];
        ty = y + dy[(d+1)%4];
        if(f(tx,ty) && s[tx][ty] == '#' && abs(hx - tx) <= 1 && abs(hy - ty) <= 1){
            if(g[x][y][d][h] < g[x][y][d][2]){
                g[x][y][d][2] = g[x][y][d][h];
                q.push(in(x,y,d,2));
                //cout << " " << x << " " << y << " " << d << " " << 2 << " " << g[x][y][d][2] << endl;
            }
        }

        tx = x + dx[(d+1)%4] + dx[(d+2)%4];
        ty = y + dy[(d+1)%4] + dy[(d+2)%4];
        if(f(tx,ty) && s[tx][ty] == '#' && abs(hx - tx) <= 1 && abs(hy - ty) <= 1){
            if(g[x][y][d][h] < g[x][y][d][3]){
                g[x][y][d][3] = g[x][y][d][h];
                q.push(in(x,y,d,3));
                //cout << " " << x << " " << y << " " << d << " " << 3 << " " << g[x][y][d][3] << endl;
            }
        }

    }

    //rep(i,n)cout << s[i] << endl;
    int x,y,cost = INF;
    rep(i,n)rep(j,m)if(s[i][j] == 'G'){
        x = i, y = j;
        rep(k,4)rep(l,4)cost = min(cost, g[i][j][k][l]);
        if(cost == INF){
            cout << -1 << endl;
            return 0;
        }
    }

    vector<vi> used(n,vi(m));
    used[x][y]++;
    while(cost){
        //cout << x << " " << y << " " << cost << endl;
        rep(i,4){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(!f(nx,ny))continue;
            rep(k,4)rep(l,4){
                if(g[nx][ny][k][l] == cost - 1){
                    x = nx;
                    y = ny;
                    cost--;
                    used[x][y]++;
                    i = k = l = 4;
                    break;
                }
            }
        }
    }

    int ans = 0;
    rep(i,n)rep(j,m)if(used[i][j])ans++;
    cout << ans << endl;

}


/*

0:正面　dx[d], dy[d]
1:斜め右前　dx[d]+dx[d+1], dy[d]+dy[d+1]
2:右 　dx[d+1], dy[d+1]
3:斜め右後ろ　dx[d+1]+dx[d+2], dy[d+1]+dy[d+2]

g[x][y][向き][手]=進んだマス目の数 で最短経路を求める
経路復元して使ったマスをusedで管理、最後に数えて出力
*/



Measured memory_bytes: 3644