#include <bits/stdc++.h>
using namespace std;
char brd[2002][2002];
bool vis[2002][2002];
int qval[2002][2002];
int ends[2002][2002];
int dp[2002][2002];
pair<pair<int, int>, pair<int, int> > res[2002][2002];
int n, m;
int theend(int ci, int cj, int pi, int pj, pair<int, int>& e1,
           pair<int, int>& e2) {
  int& ans = dp[ci][cj];
  if (ans >= 0) {
    e1 = res[ci][cj].first;
    e2 = res[ci][cj].second;
    return ans;
  }
  int cci = ci, ccj = cj;
  ans = 0;
  while (brd[ci][cj] != '#') {
    if (brd[ci][cj] == '<') {
      pi = ci;
      pj = cj;
      cj--;
    } else if (brd[ci][cj] == '>') {
      pi = ci;
      pj = cj;
      cj++;
    } else if (brd[ci][cj] == '^') {
      pi = ci;
      pj = cj;
      ci--;
    } else if (brd[ci][cj] == 'v') {
      pi = ci;
      pj = cj;
      ci++;
    }
    ans++;
  }
  e1 = pair<int, int>(ci, cj);
  e2 = pair<int, int>(pi, pj);
  res[cci][ccj] = pair<pair<int, int>, pair<int, int> >(e1, e2);
  return ans;
}
bool degen() {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (brd[i][j] != '#') return false;
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", brd[i]);
  if (degen()) {
    cout << "0\n";
    return 0;
  }
  bool hascycle = false;
  int qv = 0;
  for (int si = 0; si < n; si++)
    for (int sj = 0; sj < m; sj++) {
      if (vis[si][sj] || brd[si][sj] == '#') continue;
      qv++;
      int ci = si;
      int cj = sj;
      while (brd[ci][cj] != '#') {
        if (qval[ci][cj] == qv) {
          hascycle = true;
          break;
        }
        if (vis[si][sj]) break;
        qval[ci][cj] = qv;
        vis[si][sj] = true;
        if (brd[ci][cj] == '<') cj--;
        if (brd[ci][cj] == '>') cj++;
        if (brd[ci][cj] == '^') ci--;
        if (brd[ci][cj] == 'v') ci++;
      }
    }
  if (hascycle) {
    cout << "-1\n";
    return 0;
  }
  memset(qval, 0, sizeof(qval));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (brd[i][j] != '#') {
        if (brd[i][j] == '<') qval[i][j - 1]++;
        if (brd[i][j] == '>') qval[i][j + 1]++;
        if (brd[i][j] == '^') qval[i - 1][j]++;
        if (brd[i][j] == 'v') qval[i + 1][j]++;
      }
  memset(dp, -1, sizeof(dp));
  int mval = -1, mcnt = 0;
  set<pair<pair<int, int>, pair<int, int> > > ends;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (brd[i][j] != '#' && qval[i][j] == 0) {
        pair<int, int> x, y;
        int v = theend(i, j, i, j, x, y);
        if (v == mval) {
          mcnt++;
          ends.insert(pair<pair<int, int>, pair<int, int> >(x, y));
        } else if (v > mval) {
          mval = v;
          mcnt = 1;
          ends.clear();
          ends.insert(pair<pair<int, int>, pair<int, int> >(x, y));
        }
      }
  if (mcnt == 1 || ends.size() == 1) {
    cout << 2 * mval - 1 << endl;
  } else {
    cout << 2 * mval << endl;
  }
}
