#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
char ss[] = "<>^v";
int n, m;
char s[2005][2005];
int num, max1, max2;
int dfs(int x, int y) {
  int dq, dqmax = 0;
  ++num;
  for (int i = 0; i < 4; ++i) {
    int xx, yy;
    xx = x + dx[i];
    yy = y + dy[i];
    if (xx < 0 || xx >= n) continue;
    if (yy < 0 || yy >= m) continue;
    if (s[xx][yy] != ss[i]) continue;
    if (s[x][y] == '#') {
      dq = dfs(xx, yy);
      if (dq >= max1) {
        max2 = max1;
        max1 = dq;
      } else if (dq >= max2)
        max2 = dq;
    } else
      dqmax = max(dqmax, dfs(xx, yy));
  }
  return dqmax + 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", s[i]);
  num = 0;
  max1 = 0;
  max2 = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      if (s[i][j] == '#') dfs(i, j);
    }
  if (num != n * m) {
    printf("-1\n");
    return 0;
  }
  int ans;
  if (max1 == max2)
    ans = max1 + max2;
  else
    ans = 2 * max1 - 1;
  printf("%d\n", ans);
  return 0;
}
