#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int INF = 1 << 20;
const string dirs = "^>v<";
const int dy[4] = {-1, 0, 1, 0};
const int dx[4] = {0, 1, 0, -1};
int N, M;
string s[55];
int dis[55][55][4][4];
using P = tuple<int, int, int, int>;
P pre[55][55][4][4];

bool contain(int y, int x) {
  return y >= 0 && y < N && x >= 0 && x < M;
}

void hand(int y, int x, int d, int h, int &hy, int &hx) {
  hy = y + dy[d];
  hx = x + dx[d];
  if (h >= 1) {
    hy += dy[(d + 1) % 4];
    hx += dx[(d + 1) % 4];
  }
  if (h >= 2) {
    hy += dy[(d + 2) % 4];
    hx += dx[(d + 2) % 4];
  }
  if (h >= 3) {
    hy += dy[(d + 2) % 4];
    hx += dx[(d + 2) % 4];
  }
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M;
  N += 2; M += 2;
  for (int i = 1; i < N - 1; i++) {
    cin >> s[i];
    s[i] = "#" + s[i] + "#";
  }
  s[0] = s[N - 1] = string(M, '#');

  queue<P> que;
  fill_n((int*)dis, 55 * 55 * 4 * 4, INF);
  fill_n((P*)pre, 55 * 55 * 4 * 4, P(-1, -1, -1, -1));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      int dir = dirs.find(s[i][j]);
      if (dir == string::npos) continue;
      dis[i][j][dir][2] = 0;
      que.emplace(i, j, dir, 2);
    }
  }
  while (!que.empty()) {
    int y, x, d, h;
    tie(y, x, d, h) = que.front();
    que.pop();
    int hy, hx, ny, nx;
    int curr = dis[y][x][d][h];
    if (h == 0) {
      hand(y, x, d, 1, hy, hx);
      if (contain(hy, hx) && s[hy][hx] == '#' && dis[y][x][d][1] == INF) {
        dis[y][x][d][1] = curr + 1;
        pre[y][x][d][1] = P(y, x, d, h);
        que.emplace(y, x, d, 1);
      }
      hand(y, x, d, 2, hy, hx);
      if (contain(hy, hx) && s[hy][hx] == '#' && dis[y][x][d][2] == INF) {
        dis[y][x][d][2] = curr + 1;
        pre[y][x][d][2] = P(y, x, d, h);
        que.emplace(y, x, d, 2);
      }
      if (dis[y][x][(d + 3) % 4][2] == INF) {
        dis[y][x][(d + 3) % 4][2] = curr + 1;
        pre[y][x][(d + 3) % 4][2] = P(y, x, d, h);
        que.emplace(y, x, (d + 3) % 4, 2);
      }
    } else if (h == 1) {
      hand(y, x, d, 0, hy, hx);
      if (contain(hy, hx) && s[hy][hx] == '#' && dis[y][x][d][0] == INF) {
        dis[y][x][d][0] = curr + 1;
        pre[y][x][d][0] = P(y, x, d, h);
        que.emplace(y, x, d, 0);
      }
      hand(y, x, d, 2, hy, hx);
      if (contain(hy, hx) && s[hy][hx] == '#' && dis[y][x][d][2] == INF) {
        dis[y][x][d][2] = curr + 1;
        pre[y][x][d][2] = P(y, x, d, h);
        que.emplace(y, x, d, 2);
      }
      ny = y + dy[d];
      nx = x + dx[d];
      if (contain(ny, nx) && s[ny][nx] != '#' && dis[ny][nx][d][3] == INF) {
        dis[ny][nx][d][3] = curr + 1;
        pre[ny][nx][d][3] = P(y, x, d, h);
        que.emplace(ny, nx, d, 3);
      }
      if (dis[y][x][(d + 3) % 4][3] == INF) {
        dis[y][x][(d + 3) % 4][3] = curr + 1;
        pre[y][x][(d + 3) % 4][3] = P(y, x, d, h);
        que.emplace(y, x, (d + 3) % 4, 3);
      }
    } else if (h == 2) {
      hand(y, x, d, 0, hy, hx);
      if (contain(hy, hx) && s[hy][hx] == '#' && dis[y][x][d][0] == INF) {
        dis[y][x][d][0] = curr + 1;
        pre[y][x][d][0] = P(y, x, d, h);
        que.emplace(y, x, d, 0);
      }
      hand(y, x, d, 1, hy, hx);
      if (contain(hy, hx) && s[hy][hx] == '#' && dis[y][x][d][1] == INF) {
        dis[y][x][d][1] = curr + 1;
        pre[y][x][d][1] = P(y, x, d, h);
        que.emplace(y, x, d, 1);
      }
      hand(y, x, d, 3, hy, hx);
      if (contain(hy, hx) && s[hy][hx] == '#' && dis[y][x][d][3] == INF) {
        dis[y][x][d][3] = curr + 1;
        pre[y][x][d][3] = P(y, x, d, h);
        que.emplace(y, x, d, 3);
      }
      ny = y + dy[d];
      nx = x + dx[d];
      if (contain(ny, nx) && s[ny][nx] != '#' && dis[ny][nx][d][3] == INF) {
        dis[ny][nx][d][3] = curr + 1;
        pre[ny][nx][d][3] = P(y, x, d, h);
        que.emplace(ny, nx, d, 3);
      }
      if (dis[y][x][(d + 1) % 4][0] == INF) {
        dis[y][x][(d + 1) % 4][0] = curr + 1;
        pre[y][x][(d + 1) % 4][0] = P(y, x, d, h);
        que.emplace(y, x, (d + 1) % 4, 0);
      }
    } else {
      hand(y, x, d, 2, hy, hx);
      if (contain(hy, hx) && s[hy][hx] == '#' && dis[y][x][d][2] == INF) {
        dis[y][x][d][2] = curr + 1;
        pre[y][x][d][2] = P(y, x, d, h);
        que.emplace(y, x, d, 2);
      }
      if (dis[y][x][(d + 1) % 4][1] == INF) {
        dis[y][x][(d + 1) % 4][1] = curr + 1;
        pre[y][x][(d + 1) % 4][1] = P(y, x, d, h);
        que.emplace(y, x, (d + 1) % 4, 1);
      }
    }
  }
  int gy, gx;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (s[i][j] == 'G') {
        gy = i; gx = j;
      }
    }
  }
  int ans = INF;
  for (int d = 0; d < 4; d++) {
    for (int h = 0; h < 4; h++) {
      set<pii> st;
      P curr = P(gy, gx, d, h);
      if (dis[gy][gx][d][h] == INF) continue;
      while (curr != P(-1, -1, -1, -1)) {
        int y, x, d, h;
        tie(y, x, d, h) = curr;
        st.emplace(y, x);
        curr = pre[y][x][d][h];
      }
      ans = min(ans, (int)st.size());
    }
  }
  cout << (ans == INF ? -1 : ans) << endl;

  return 0;
}


Measured memory_bytes: 4216