#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T& x) {
  bool fu = 0;
  char c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  if (c == '-') fu = 1, c = getchar();
  for (x = 0; c > 32; c = getchar()) x = x * 10 + c - '0';
  if (fu) x = -x;
};
char getc() {
  char c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  return c;
}
const int N = 2010;
const int f1[] = {0, 0, 1, -1};
const int f2[] = {1, -1, 0, 0};
int gg(char c) {
  if (c == '<') return 0;
  if (c == '>') return 1;
  if (c == '^') return 2;
  if (c == 'v') return 3;
  return -1;
}
int n, m, i, j, k, l, p, t, x, y, x2, y2, g, head, tail, s0, n0, s1, n1;
char a[N][N];
bool have, oo;
int q[N * N][2], d[N][N], s[N][N];
bool v[N][N];
bool pd(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m; }
int main() {
  read(n);
  read(m);
  for (i = 1; i <= n; i++) scanf("%s", a[i] + 1);
  int cnt = 0;
  head = 1;
  tail = 0;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      if (a[i][j] == '#') {
        ++tail;
        q[tail][0] = i;
        q[tail][1] = j;
        s[i][j] = -1;
        v[i][j] = 1;
      } else {
        cnt++;
      }
  for (; head <= tail; head++) {
    x = q[head][0];
    y = q[head][1];
    for (t = 0; t <= 3; t++) {
      x2 = x + f1[t];
      y2 = y + f2[t];
      if (pd(x2, y2) && gg(a[x2][y2]) == t) {
        if (v[x2][y2]) {
          printf("-1\n");
          return 0;
        }
        ++tail;
        have = 1;
        ++g;
        q[tail][0] = x2;
        q[tail][1] = y2;
        d[x2][y2] = d[x][y] + 1;
        if (a[x][y] == '#')
          s[x2][y2] = (x2 - 1) * m + y2;
        else
          s[x2][y2] = s[x][y];
      }
    }
  }
  if (g != cnt) {
    printf("-1\n");
    return 0;
  }
  int ans = 0;
  ans = s0 = d[q[tail][0]][q[tail][1]];
  n0 = s[q[tail][0]][q[tail][1]];
  for (i = tail - 1; i >= 1; i--) {
    ans =
        max(ans, s0 + d[q[i][0]][q[i][1]] -
                     (s[q[i][0]][q[i][1]] == n0 && d[q[i][0]][q[i][1]] == s0));
  }
  printf("%d\n", ans);
  scanf("\n");
  return 0;
}
