#include <bits/stdc++.h>
using namespace std;
const int N = 2100;
const long long mod = 1000000007;
char mat[N][N];
int n, m;
int vis[N][N];
int endpoint[N][N][2], len[N][N];
bool havecircle = false;
int dfs(int x, int y, int cnt, int px, int py, int &ex, int &ey) {
  if (mat[x][y] == '#') {
    vis[x][y] = cnt;
    ex = px;
    ey = py;
    return len[x][y] = 0;
  }
  if (vis[x][y] == cnt) havecircle = true;
  if (havecircle) return 0;
  if (vis[x][y]) {
    ex = endpoint[x][y][0];
    ey = endpoint[x][y][1];
    return len[x][y];
  }
  vis[x][y] = cnt;
  if (mat[x][y] == 'v') len[x][y] = 1 + dfs(x + 1, y, cnt, x, y, ex, ey);
  if (mat[x][y] == '<') len[x][y] = 1 + dfs(x, y - 1, cnt, x, y, ex, ey);
  if (mat[x][y] == '>') len[x][y] = 1 + dfs(x, y + 1, cnt, x, y, ex, ey);
  if (mat[x][y] == '^') len[x][y] = 1 + dfs(x - 1, y, cnt, x, y, ex, ey);
  endpoint[x][y][0] = ex;
  ey = endpoint[x][y][1] = ey;
  return len[x][y];
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) scanf("%s", &mat[i]);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int ans = 0;
      int x, y;
      if (!vis[i][j] && !havecircle && mat[i][j] != '#')
        dfs(i, j, ++cnt, i, j, x, y);
    }
  }
  if (havecircle)
    cout << -1 << endl;
  else {
    int mmax = 0, smax = 0;
    int exx, eyy;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        if (mat[i][j] == '#') continue;
        if (mmax < len[i][j]) {
          mmax = len[i][j];
          smax = mmax - 1;
          exx = endpoint[i][j][0];
          eyy = endpoint[i][j][1];
        } else if (smax < len[i][j]) {
          smax = len[i][j];
          if (endpoint[i][j][0] == exx && endpoint[i][j][1] == eyy) smax--;
        }
      }
    cout << mmax + smax << endl;
  }
}
