#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

//const int dx[] = { -1, 0, 0, 1 }, dy[] = { 0, -1, 1, 0 };
//[const int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 }, dy[] = { 0, -1, 1, -1, 1, 0, -1, 1 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
int place(int x, int y, int w) { return w*x + y; }
int dx[4][4] =
{
	{ -1,0,1,0 },
	{ 0,1,0,-1 },
	{ 1,0,-1,0 },
	{ 0,-1,0,1 }
};
int dy[4][4] =
{
	{ 0,-1,0,1 },
	{ -1,0,1,0 },
	{ 0,1,0,-1 },
	{ 1,0,-1,0 }
};

int h, w;
vs fld;
bool hand(int x, int y, int dir, int p)
{
	int dx[4][5] =
	{
		{-1,-1,0 ,1 ,0 },
		{0 ,-1,-1,-1,1 },
		{1 ,1 ,0 ,-1,0 },
		{0 ,1 ,1 ,1 ,-1}
	};
	int dy[4][5] = 
	{
		{ 0, 1, 1, 1,-1},
		{-1,-1, 0, 1, 0},
		{ 0,-1,-1,-1, 1},
		{ 1, 1, 0,-1, 0}
	};
	return fld[x + dx[dir][p]][y + dy[dir][p]] == '#';
}


typedef tuple<int, int, int, int> Data;

int main()
{
	cin.sync_with_stdio(false);
	cin >> h >> w;
	h += 2, w += 2;
	fld.resize(h);
	fld[0] = fld[h - 1] = string(w, '#');
	REP(i, h-2)
	{
		string s; cin >> s;
		fld[i + 1] = "#" + s + "#";
	}
	int sx, sy, sdir, gx, gy;
	REP(i, h)REP(j, w)
	{
		if (fld[i][j] == '^')
		{
			sx = i, sy = j, sdir = 0;
			fld[i][j] = '.';
		}
		if (fld[i][j] == '<')
		{
			fld[i][j] = '.';
			sx = i, sy = j, sdir = 1;
		}
		if (fld[i][j] == 'v')
		{
			fld[i][j] = '.';
			sx = i, sy = j, sdir = 2;
		}
		if (fld[i][j] == '>')
		{
			fld[i][j] = '.';
			sx = i, sy = j, sdir = 3;
		}
		if (fld[i][j] == 'G')
		{
			fld[i][j] = '.';
			gx = i, gy = j;
		}
	}
	set<Data> st;
	set<pii> vis;
	Data tmp = Data{ sx,sy, sdir,2 };
	while (1)
	{

		if (st.count(tmp))
		{
			puts("-1");
			break;
		}
		if (get<0>(tmp) == gx && get<1>(tmp) == gy)
		{
			cout << vis.size() + 1 << endl;
			break;
		}
		int tx = get<0>(tmp), ty = get<1>(tmp), tdir = get<2>(tmp);
		st.insert(tmp);
		vis.insert(pii(tx, ty));
		int nx, ny;
		//straight
		nx = tx + dx[tdir][0], ny = ty + dy[tdir][0];
		if (fld[nx][ny] != '#')
		{
			if (hand(tx, ty, tdir, 2))
			{
				tmp = Data{ nx,ny,tdir, 3 };
				continue;
			}
		}
		//left
		nx = tx + dx[tdir][1], ny = ty + dy[tdir][1];
		if (fld[nx][ny] != '#')
		{
			if (get<3>(tmp) == 3)
			{
				if (hand(tx, ty, tdir, 2)) get<3>(tmp) = 2;
			}
			if (get<3>(tmp) == 0 || get<3>(tmp) == 1 || get<3>(tmp) == 2)
			{
				tmp = Data{ nx,ny,(tdir + 1) % 4,3 };
				continue;
			}
		}
		//back
		nx = tx + dx[tdir][2], ny = ty + dy[tdir][2];
		if (fld[nx][ny] != '#')
		{
			if (get<3>(tmp) == 3)
			{
				if (hand(tx, ty, tdir, 2)) get<3>(tmp) = 2;
			}
			if (get<3>(tmp) == 1 || get<3>(tmp) == 2)
			{
				if (hand(tx, ty, tdir, 0)) get<3>(tmp) = 0;
			}
			if (get<3>(tmp) == 0 && hand(tx,ty,tdir, 4))
			{
				tmp = Data{ nx,ny,(tdir + 2) % 4,3 };
				continue;
			}
		}
		//right
		nx = tx + dx[tdir][3], ny = ty + dy[tdir][3];
		if (fld[nx][ny] != '#')
		{
			if (get<3>(tmp) == 3)
			{
				tmp = Data{ nx,ny,(tdir + 3) % 4, 2 };
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3436