#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>


template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

int rh[4][4] = {
	{1,0,-1,-1},{1,1,1,0},{-1,0,1,1},{-1,-1,-1,0}
};

int rw[4][4] = {
	{1,1,1,0},{-1,0,1,1},{-1,-1,-1,0},{1,0,-1,-1}
};

int dh[4] = { -1,0,1,0 };
int dw[4] = { 0,1,0,-1 };

int H, W;
int f(int h, int w, int k, int l) {
	return l * H * W * 4 + k * H * W + h * W + w;
}

tuple<int,int,int,int> b(int X) {
	int l = X / (H * W * 4);
	int k = (X % (H * W * 4)) / (H * W);
	int h = (X % (H * W)) / W;
	int w = X % W;
	return make_tuple(h, w, k, l);
}

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	cin >> H >> W;
	vector<string> vs(H + 2, string(W + 2, '#'));
	for (int i = 1; i <= H; i++) {
		string s; cin >> s;
		for (int j = 1; j <= W; j++) vs[i][j] = s[j - 1];
	}
	H += 2;
	W += 2;
	vector<vector<int>> g(H * W * 4 * 4);
	int gh = -1, gw = -1;
	int sh = -1, sw = -1, ss = -1;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (vs[i][j] == '#') continue;
			if (vs[i][j] == 'G') gh = i, gw = j;
			if (vs[i][j] == '^') sh = i, sw = j, ss = 0;
			if (vs[i][j] == '>') sh = i, sw = j, ss = 1;
			if (vs[i][j] == 'v') sh = i, sw = j, ss = 2;
			if (vs[i][j] == '<') sh = i, sw = j, ss = 3;
			for (int k = 0; k < 4; k++) {
				for (int l = 0; l < 4; l++) {
					int RH = i + rh[k][l];
					int RW = j + rw[k][l];
					if (RH < 0 or RH >= H or RW < 0 or RW >= W) continue;
					if (vs[RH][RW] != '#') continue;
					//ここから状態としてはあり得る状態
					int cur = f(i, j, k, l);
					//右手の移動
					if (l) {
						int nRH = i + rh[k][l - 1];
						int nRW = j + rw[k][l - 1];
						if (!(nRH < 0 or nRH >= H or nRW < 0 or nRW >= W)) {
							if (!(vs[nRH][nRW] != '#')) {
								g[cur].emplace_back(f(i, j, k, l - 1));
							}
						}
					}
					if (l == 3) {
						int nRH = i + rh[k][l - 2];
						int nRW = j + rw[k][l - 2];
						if (!(nRH < 0 or nRH >= H or nRW < 0 or nRW >= W)) {
							if (!(vs[nRH][nRW] != '#')) {
								g[cur].emplace_back(f(i, j, k, l - 2));
							}
						}
					}
					if (l + 1 < 4) {
						int nRH = i + rh[k][l + 1];
						int nRW = j + rw[k][l + 1];
						if (!(nRH < 0 or nRH >= H or nRW < 0 or nRW >= W)) {
							if (!(vs[nRH][nRW] != '#')) g[cur].emplace_back(f(i, j, k, l + 1));
						}
					}
					if (l == 1) {
						int nRH = i + rh[k][l + 2];
						int nRW = j + rw[k][l + 2];
						if (!(nRH < 0 or nRH >= H or nRW < 0 or nRW >= W)) {
							if (!(vs[nRH][nRW] != '#')) {
								g[cur].emplace_back(f(i, j, k, l + 2));
							}
						}
					}

					//回転
					{
						int nk = k + 1; if (nk >= 4) nk -= 4;
						int nl = l + 2;
						if (nl < 4) {
							g[cur].emplace_back(f(i, j, nk, nl));
						}
					}
					{
						int nk = k - 1; if (nk < 0) nk += 4;
						int nl = l - 2;
						if (nl >= 0) {
							g[cur].emplace_back(f(i, j, nk, nl));
						}
					}

					//移動
					{
						int nh = i + dh[k];
						int nw = j + dw[k];
						if (!(nh < 0 or nh >= H or nw < 0 or nw >= W)) {
							if (!(vs[nh][nw] == '#')) {
								int nl = l - 1;
								if (nl >= 0) {
									g[cur].emplace_back(f(nh, nw, k, nl));
								}
							}
						}
					}
				}
			}
		}
	}

	int cur = f(sh, sw, ss, 1);
	vector<vector<bool>> visited(H, vector<bool>(W));
	vector<bool> used(H * W * 4 * 4);
	visited[sh][sw] = true;
	used[cur] = true;
	queue<tuple<int, int, int, int>> q;
	q.emplace(sh, sw, ss, 1);
	bool ok = false;
	//for (int i = 0; i < H; i++) cout << vs[i] << endl;
	while (!q.empty()) {
		int h, w, k, l; tie(h, w, k, l) = q.front();
		//cout << h << " " << w << " " << k << " " << l << endl;
		q.pop();
		int cur = f(h, w, k, l);
		for (auto nxt : g[cur]) {
			if (used[nxt]) continue;
			int nh, nw, nk, nl; tie(nh, nw, nk, nl) = b(nxt);
			used[nxt] = true;
			visited[nh][nw] = true;
			if (nh == gh and nw == gw) {
				ok = true;
				break;
			}
			q.emplace(nh, nw, nk, nl);
		}
	}
	int res = 0; for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) res += visited[i][j];
	if (!ok) res = -1;
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 4504