#include <bits/stdc++.h>
using namespace std;
const int di[] = {-1, 1, 0, 0};
const int dj[] = {0, 0, -1, 1};
const char dc[] = {'^', 'v', '<', '>'};
const int MN = 2011;
int m, n, cur;
char a[MN][MN];
int next_[MN * MN], to[MN * MN], head[MN * MN];
int visited[MN * MN], vao[MN * MN], f1[MN * MN];
bool dfs1(int u, int fu) {
  visited[u] = 1;
  for (int p = head[u]; p >= 0; p = next_[p]) {
    int v = to[p];
    if (!visited[v]) {
      if (dfs1(v, u)) return true;
    } else if (visited[v] == 1)
      return true;
  }
  visited[u] = 2;
  return false;
}
void dfs2(int u) {
  f1[u] = visited[u];
  for (int p = head[u]; p >= 0; p = next_[p]) {
    int v = to[p];
    if (!visited[v]) {
      visited[v] = visited[u] + 1;
      dfs2(v);
    }
    f1[u] = max(f1[u], f1[v]);
  }
}
bool hasCycle() {
  memset(visited, 0, sizeof visited);
  for (int i = (1), _b = (cur); i <= _b; i++)
    if (!visited[i]) {
      if (dfs1(i, -1)) return true;
    }
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout << (fixed) << setprecision(6);
  while (cin >> m >> n) {
    for (int i = (1), _b = (m); i <= _b; i++)
      for (int j = (1), _b = (n); j <= _b; j++) cin >> a[i][j];
    cur = 0;
    for (int i = (1), _b = (m); i <= _b; i++)
      for (int j = (1), _b = (n); j <= _b; j++)
        if (a[i][j] != '#') {
          ++cur;
        }
    if (cur < 2) {
      cout << 0 << endl;
      continue;
    }
    cur = m * n;
    memset(vao, 0, sizeof vao);
    memset(head, -1, sizeof head);
    memset(next_, -1, sizeof next_);
    memset(to, 0, sizeof to);
    int nEdges = 0;
    for (int i = (1), _b = (m); i <= _b; i++)
      for (int j = (1), _b = (n); j <= _b; j++)
        if (a[i][j] != '#') {
          for (int dir = 0, _a = (4); dir < _a; dir++)
            if (dc[dir] == a[i][j]) {
              int ii = i + di[dir], jj = j + dj[dir];
              if (a[ii][jj] != '#') {
                int u = (i - 1) * n + j, v = (ii - 1) * n + jj;
                swap(u, v);
                next_[nEdges] = head[u];
                to[nEdges] = v;
                head[u] = nEdges++;
                vao[v]++;
              }
            }
        }
    if (hasCycle()) {
      cout << -1 << endl;
      continue;
    }
    memset(visited, 0, sizeof visited);
    int ln1 = 0, ln2 = 0, res = 0;
    for (int i = (1), _b = (cur); i <= _b; i++)
      if (!vao[i]) {
        visited[i] = 1;
        dfs2(i);
        res = max(res, f1[i] + f1[i] - 1);
        if (f1[i] > ln1) {
          ln2 = ln1;
          ln1 = f1[i];
        } else if (f1[i] > ln2) {
          ln2 = f1[i];
        }
        res = max(res, ln1 + ln2);
      }
    cout << res << endl;
  }
  return 0;
}
