#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

// 下、右、上、左
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int d[55][55][4][4];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int h, w;
  cin >> h >> w;
  h += 2, w += 2;
  vector<string> s(h);
  s[0] = s[h-1] = string(w, '#');
  FOR(i, 1, h-1) {
    cin >> s[i];
    s[i] = "#" + s[i] + "#";
  }

  int sx=-1, sy=-1, sdir=-1, gx=-1, gy=-1;
  REP(i, h) REP(j, w) {
    if(s[i][j] == 'v') {
      sdir = 0, sx = j, sy = i;
    } else if(s[i][j] == '>') {
      sdir = 1, sx = j, sy = i;
    } else if(s[i][j] == '^') {
      sdir = 2, sx = j, sy = i;
    } else if(s[i][j] == '<') {
      sdir = 3, sx = j, sy = i;
    } else if(s[i][j] == 'G') {
      gx = j, gy = i;
    }
  }

  VVI used(h, VI(w, 0));
  int x = sx, y = sy, dir = sdir, cnt = 0;
  while(x!=gx||y!=gy) {
    // cout << x << " " << y << " " << dir << endl;
    used[y][x] = 1;
    int tmpx = x + dx[(dir+3)%4], tmpy = y + dy[(dir+3)%4];
    bool right = s[tmpy][tmpx]=='#';
    tmpx = x + dx[dir], tmpy = y + dy[dir];
    bool front = s[tmpy][tmpx]=='#';
    tmpx = x + dx[(dir+1)%4], tmpy = y + dy[(dir+1)%4];
    bool left = s[tmpy][tmpx]=='#';
    if(!right) {
      // cout << "r" << endl;
      dir = (dir+3)%4, x += dx[dir], y += dy[dir];
    } else if(right && !front) {
      // cout << "f" << endl;
      x += dx[dir], y += dy[dir];
    } else if(!left) {
      // cout << "l" << endl;
      dir = (dir+1)%4, x += dx[dir], y += dy[dir];
    } else {
      dir = (dir+2)%4, x += dx[dir], y += dy[dir];
    }
    cnt++;
    if(cnt > 20000) {
      cout << -1 << endl;
      return 0;
    }
  }

  int ans = 1;
  REP(i, h) REP(j, w) ans += used[i][j];
  cout << ans << endl;

  return 0;
}

