#include <bits/stdc++.h>
using namespace std;
class TaskD {
  int N, mx, smx;
  vector<bool> vis;
  vector<int> dis, deg, next;
  void dfs(int u) {
    vis[u] = true;
    if (next[u] == -1) {
      return;
    }
    dis[next[u]] = max(dis[next[u]], dis[u] + 1);
    if (next[next[u]] == -1) {
      if (dis[u] + 1 > mx) {
        smx = mx;
        mx = dis[u] + 1;
      } else if (dis[u] + 1 > smx) {
        smx = dis[u] + 1;
      }
    }
    deg[next[u]]--;
    if (!deg[next[u]]) {
      dfs(next[u]);
    }
  }

 public:
  TaskD(int n, int m) {
    N = n * m;
    mx = 0, smx = 0;
    vis.assign(N, false);
    deg.assign(N, 0);
    dis.assign(N, 0);
    next.resize(N);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        char c;
        cin >> c;
        if (c == '#') {
          next[i * m + j] = -1;
        } else if (c == '>') {
          next[i * m + j] = (i * m + j + 1);
          deg[i * m + j + 1]++;
        } else if (c == '<') {
          next[i * m + j] = (i * m + j - 1);
          deg[i * m + j - 1]++;
        } else if (c == '^') {
          next[i * m + j] = ((i - 1) * m + j);
          deg[(i - 1) * m + j]++;
        } else if (c == 'v') {
          next[i * m + j] = ((i + 1) * m + j);
          deg[(i + 1) * m + j]++;
        } else {
          assert(false);
        }
      }
    }
  }
  void solve() {
    for (int u = 0; u < N; u++) {
      if (!deg[u] and !vis[u]) {
        dfs(u);
      }
    }
    if (count(deg.begin(), deg.end(), 0) != N) {
      cout << -1 << '\n';
      return;
    }
    int res = mx + mx;
    if (mx != smx) res--;
    cout << res << '\n';
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  TaskD D(n, m);
  D.solve();
}
