#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int INF = 0x7fffffff;
const long long linf = 1LL << 60;
const int N = 2000;
int n, m;
char str[N + 5][N + 5];
void input() {
  scanf("%d %d", &n, &m);
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) scanf("%s", str[i]);
}
int ans;
bool vis[N + 5][N + 5];
int mx[N + 5][N + 5];
int dx[256], dy[256];
int D[] = {0, -1, 0, 1, 0};
inline bool in(int x, int y) {
  if (x < 0 || x >= n) return false;
  if (y < 0 || y >= m) return false;
  return true;
}
inline void chk_max(int &x, int &y, int z) {
  if (z >= x) {
    y = x;
    x = z;
  } else if (z >= y) {
    y = z;
  }
}
struct con {
  int x, y, dep;
} q[N * N + 5];
void bfs() {
  int L = 0, H = 0;
  for (int i = (0), i_end_ = (n); i < i_end_; ++i)
    for (int j = (0), j_end_ = (m); j < j_end_; ++j)
      if (str[i][j] != '#') {
        char c = str[i][j];
        int tx = i + dx[c], ty = j + dy[c];
        if (!in(tx, ty)) continue;
        if (str[tx][ty] == '#') q[H++] = (con){i, j, 1};
      }
  while (L < H) {
    int x = q[L].x, y = q[L].y, dep = q[L].dep;
    L++;
    assert(vis[x][y] == false);
    vis[x][y] = true;
    for (int i = (0), i_end_ = (4); i < i_end_; ++i) {
      int tx = x + D[i], ty = y + D[i + 1];
      if (!in(tx, ty)) continue;
      char c = str[tx][ty];
      if (c == '#') continue;
      if (tx + dx[c] == x && ty + dy[c] == y) q[H++] = (con){tx, ty, dep + 1};
    }
  }
  for (int i = (H)-1, i_begin_ = (0); i >= i_begin_; --i) {
    int x = q[i].x, y = q[i].y, dep = q[i].dep;
    int mx1 = dep, mx2 = 0;
    for (int i = (0), i_end_ = (4); i < i_end_; ++i) {
      int tx = x + D[i], ty = y + D[i + 1];
      if (!in(tx, ty)) continue;
      char c = str[tx][ty];
      if (c == '#') continue;
      if (tx + dx[c] == x && ty + dy[c] == y) chk_max(mx1, mx2, mx[tx][ty]);
    }
    int tmp = mx1 + mx2;
    if (mx1 == mx2) tmp--;
    if (tmp > ans) ans = tmp;
    mx[x][y] = mx1;
  }
}
void solve() {
  ans = 0;
  for (int i = (0), i_end_ = (n); i < i_end_; ++i)
    for (int j = (0), j_end_ = (m); j < j_end_; ++j) vis[i][j] = false;
  bfs();
  int mx1 = 0, mx2 = 0;
  for (int i = (0), i_end_ = (n); i < i_end_; ++i)
    for (int j = (0), j_end_ = (m); j < j_end_; ++j)
      if (str[i][j] != '#') {
        char c = str[i][j];
        int tx = i + dx[c], ty = j + dy[c];
        if (!in(tx, ty)) continue;
        if (str[tx][ty] == '#') {
          chk_max(mx1, mx2, mx[i][j]);
        }
      }
  for (int i = (0), i_end_ = (n); i < i_end_; ++i)
    for (int j = (0), j_end_ = (m); j < j_end_; ++j)
      if (str[i][j] != '#' && !vis[i][j]) {
        puts("-1");
        return;
      }
  mx1 += mx2;
  if (mx1 > ans) ans = mx1;
  printf("%d\n", ans);
}
int main() {
  dx['^'] = -1;
  dy['^'] = 0;
  dx['v'] = 1;
  dy['v'] = 0;
  dx['<'] = 0;
  dy['<'] = -1;
  dx['>'] = 0;
  dy['>'] = 1;
  input();
  solve();
  return 0;
}
