#include <bits/stdc++.h>
using namespace std;
const int maxN = 2005;
const int dx[5] = {1, -1, 0, 0};
const int dy[5] = {0, 0, -1, 1};
int n, m, maxlen, s, t;
char a[maxN][maxN];
bool mark[maxN][maxN], ck;
int d[maxN][maxN], f[maxN][maxN];
vector<int> res;
int Id(char a) {
  if (a == 'v')
    return 0;
  else if (a == '^')
    return 1;
  else if (a == '<')
    return 2;
  else if (a == '>')
    return 3;
}
void DFS(int u, int v) {
  d[u][v] = 1;
  f[u][v] = (n - 1) * u + v;
  mark[u][v] = true;
  int id = Id(a[u][v]);
  int x = u + dx[id], y = v + dy[id];
  if (x == s && y == t) {
    ck = true;
    return;
  }
  if (!mark[x][y]) {
    if (a[x][y] != '#') {
      DFS(x, y);
      d[u][v] += d[x][y];
      f[u][v] = f[x][y];
    }
  } else {
    if (a[x][y] != '#') {
      d[u][v] += d[x][y];
      f[u][v] = f[x][y];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  scanf("%d%d\n", &n, &m);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) scanf("%c", &a[i][j]);
    scanf("\n");
  }
  memset(mark, false, sizeof mark);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (!mark[i][j] && a[i][j] != '#') {
        s = i;
        t = j;
        ck = false;
        DFS(i, j);
        if (ck) {
          cout << -1;
          return 0;
        }
        maxlen = max(maxlen, d[i][j]);
      }
  if (maxlen == 0) {
    cout << maxlen;
    return 0;
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (d[i][j] == maxlen) res.push_back(f[i][j]);
  sort(res.begin(), res.end());
  int cnt = 1;
  for (int i = 1; i <= (int)res.size() - 1; ++i)
    if (res[i] != res[i - 1]) ++cnt;
  if (cnt >= 2)
    cout << maxlen * 2;
  else
    cout << maxlen * 2 - 1;
}
