#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
inline T LCM(T a, T b) {
  if (a < 0) return LCM(-a, b);
  if (b < 0) return LCM(a, -b);
  return a * (b / gcd(a, b));
}
pair<int, int> dp[2001][2001];
int n, m;
vector<string> g;
bool cycle = false;
bool inside(int x, int y) {
  if (x < 0 || x >= n || y < 0 || y >= m) return false;
  return true;
}
void dfs(int x, int y, int depth, int path) {
  if (!inside(x, y) || g[x][y] == '#') return;
  if (dp[x][y].second == path) {
    cycle = true;
    return;
  } else if (dp[x][y].first >= depth)
    return;
  dp[x][y].first = depth;
  dp[x][y].second = path;
  if (g[x][y] == '^') dfs(x - 1, y, depth + 1, path);
  if (g[x][y] == 'v') dfs(x + 1, y, depth + 1, path);
  if (g[x][y] == '>') dfs(x, y + 1, depth + 1, path);
  if (g[x][y] == '<') dfs(x, y - 1, depth + 1, path);
}
int main() {
  int ans, maxi = 0, cnt = 2, i, j, path = 0;
  cin >> n >> m;
  g.resize(n);
  memset(dp, 0, sizeof(dp));
  for (i = (int)0; i < (int)n; ++i) cin >> g[i];
  for (i = (int)1; i < (int)n - 1; ++i) {
    for (j = (int)1; j < (int)m - 1; ++j) {
      if (g[i][j] != '#' && dp[i][j].first == 0 && g[i - 1][j] != 'v' &&
          g[i + 1][j] != '^' && g[i][j + 1] != '<' && g[i][j - 1] != '>') {
        path++;
        dfs(i, j, 1, path);
        if (cycle == true) {
          printf("%d\n", -1);
          return 0;
        }
      }
    }
  }
  for (i = (int)1; i < (int)n - 1; ++i)
    for (j = (int)1; j < (int)m - 1; ++j)
      if (g[i][j] != '#' && dp[i][j].second == 0) cycle = true;
  if (cycle) {
    printf("%d\n", -1);
    return 0;
  }
  for (i = (int)1; i < (int)n - 1; ++i) {
    for (j = (int)1; j < (int)m - 1; ++j) {
      if (dp[i][j].first >= maxi) {
        if (dp[i][j].first == maxi)
          cnt++;
        else {
          cnt = 1;
          maxi = dp[i][j].first;
        }
      }
    }
  }
  if (cnt >= 2)
    printf("%d\n", 2 * maxi);
  else
    printf("%d\n", 2 * maxi - 1);
  return 0;
}
