#include <bits/stdc++.h>
using namespace std;
static char s[3000][3000];
static int m1[3000][3000], m2[3000][3000], ind;
int dfs7(int a, int b) {
  if (s[a][b] == '#') return 0;
  if (m1[a][b]) return m1[a][b];
  if (m2[a][b] == 1) {
    ind = 1;
    return 0;
  }
  m2[a][b] = 1;
  if (s[a][b] == '>') {
    m1[a][b] = dfs7(a, b + 1) + 1;
    m2[a][b] = 0;
    return m1[a][b];
  }
  if (s[a][b] == '<') {
    m1[a][b] = dfs7(a, b - 1) + 1;
    m2[a][b] = 0;
    return m1[a][b];
  }
  if (s[a][b] == '^') {
    m1[a][b] = dfs7(a - 1, b) + 1;
    m2[a][b] = 0;
    return m1[a][b];
  }
  if (s[a][b] == 'v') {
    m1[a][b] = dfs7(a + 1, b) + 1;
    m2[a][b] = 0;
    return m1[a][b];
  }
}
void dfs8(int a, int b) {
  if (s[a][b] == '#') return;
  if (s[a][b] == '>') dfs8(a, b + 1);
  if (s[a][b] == '<') dfs8(a, b - 1);
  if (s[a][b] == '^') dfs8(a - 1, b);
  if (s[a][b] == 'v') dfs8(a + 1, b);
  s[a][b] = '#';
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, m, a = 0, b = 0, c;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> s[i];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      dfs7(i, j);
      if (ind) {
        cout << -1 << endl;
        return 0;
      }
    }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (m1[a][b] < m1[i][j]) {
        a = i;
        b = j;
      }
  c = m1[a][b];
  dfs8(a, b);
  memset(m1, 0, sizeof(m1));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) dfs7(i, j);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (m1[a][b] < m1[i][j]) {
        a = i;
        b = j;
      }
  42;
  cout << c + max(m1[a][b], c - 1) << endl;
  return 0;
}
