#include <bits/stdc++.h>
using namespace std;
char x[2010][2010];
int vis[2010][2010], res[2010][2010];
pair<int, int> get_pair(int i, int j) {
  pair<int, int> t;
  if (x[i][j] == '>')
    t = make_pair(i, j + 1);
  else if (x[i][j] == '<')
    t = make_pair(i, j - 1);
  else if (x[i][j] == '^')
    t = make_pair(i - 1, j);
  else
    t = make_pair(i + 1, j);
  return t;
}
int dfs(int i, int j, int n, int m) {
  if (vis[i][j]) return vis[i][j];
  pair<int, int> t = get_pair(i, j);
  vis[i][j] = 1;
  res[i][j] = 1;
  if (x[t.first][t.second] != '#') {
    if (!res[t.first][t.second])
      vis[i][j] = min(10000000, 1 + dfs(t.first, t.second, n, m));
    else
      vis[i][j] = 10000000;
  }
  res[i][j] = 0;
  return vis[i][j];
}
bool traverse(pair<int, int> q, pair<int, int> r) {
  if (x[q.first][q.second] == '#' && x[r.first][r.second] == '#') return 1;
  if (q == r) return 0;
  pair<int, int> s = get_pair(q.first, q.second),
                 t = get_pair(r.first, r.second);
  return 1 & traverse(s, t);
}
int main() {
  int n, m, f = 0;
  pair<int, int> q, r;
  cin >> n >> m;
  for (int i = (0); i < (n); i++) cin >> x[i];
  for (int i = (0); i < (n); i++)
    for (int j = (0); j < (m); j++)
      if (x[i][j] != '#') {
        vis[i][j] = dfs(i, j, n, m);
        if (vis[i][j] > f) {
          f = vis[i][j];
          q = make_pair(i, j);
        }
      }
  if (!f)
    cout << "0";
  else if (f == 10000000)
    cout << "-1";
  else {
    int s = 0;
    for (int i = (0); i < (n); i++)
      for (int j = (0); j < (m); j++)
        if (q != make_pair(i, j) && x[i][j] != '#') {
          if (vis[i][j] > s) {
            s = vis[i][j];
            r = make_pair(i, j);
          }
        }
    if (!s)
      cout << f;
    else if (f != s)
      cout << f + s;
    else {
      if (traverse(q, r))
        cout << 2 * f;
      else
        cout << 2 * f - 1;
    }
  }
  cout << endl;
  return 0;
}
