#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
bool ok;
int n, m, maxx;
string a[MAXN];
int dp[MAXN][MAXN], bio[MAXN][MAXN];
void dfs(int x, int y) {
  if (a[x][y] == '#') return;
  if (bio[x][y]) {
    ok = 0;
    return;
  }
  bio[x][y] = 1;
  if (a[x][y] == '>') dfs(x, y + 1);
  if (a[x][y] == 'v') dfs(x + 1, y);
  if (a[x][y] == '<') dfs(x, y - 1);
  if (a[x][y] == '^') dfs(x - 1, y);
}
int f(int x, int y) {
  if (dp[x][y] >= 0) return dp[x][y];
  if (dp[x][y] == -2) {
    cout << -1 << endl;
    exit(0);
  }
  dp[x][y] = -2;
  if (a[x][y] == '#') return dp[x][y] = 0;
  if (a[x][y] == '>') return dp[x][y] = f(x, y + 1) + 1;
  if (a[x][y] == 'v') return dp[x][y] = f(x + 1, y) + 1;
  if (a[x][y] == '<') return dp[x][y] = f(x, y - 1) + 1;
  return dp[x][y] = f(x - 1, y) + 1;
}
int main(void) {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) maxx = max(maxx, f(i, j));
  vector<pair<int, int> > p;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (dp[i][j] == maxx) p.push_back(make_pair(i, j));
  for (int i = 0; i < p.size(); i++)
    for (int j = i + 1; j < p.size(); j++) {
      memset(bio, 0, sizeof bio);
      ok = 1;
      dfs(p[i].first, p[i].second);
      dfs(p[j].first, p[j].second);
      if (ok) {
        cout << maxx * 2 << endl;
        return 0;
      }
    }
  if (maxx == 0)
    cout << 0 << endl;
  else
    cout << maxx * 2 - 1 << endl;
  return 0;
}
