#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
int n;
int m;
int was[2000][2000];
int d[2000][2000];
string s[2000];
int bad = 0;
int calc(int i, int j) {
  if (s[i][j] == '#') return 0;
  if (was[i][j] == 1) bad = 1;
  if (was[i][j]) return d[i][j];
  was[i][j] = 1;
  d[i][j] = calc(i - int(s[i][j] == '^') + int(s[i][j] == 'v'),
                 j - int(s[i][j] == '<') + int(s[i][j] == '>')) +
            1;
  was[i][j] = 2;
  return d[i][j];
}
int go(int i, int j) {
  if (s[i][j] == '#') return 1;
  if (was[i][j]) return 0;
  was[i][j] = 1;
  return go(i - int(s[i][j] == '^') + int(s[i][j] == 'v'),
            j - int(s[i][j] == '<') + int(s[i][j] == '>'));
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  int ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) ans = max(ans, d[i][j] = calc(i, j));
  int ok = 0;
  memset(was, 0, sizeof(was));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (d[i][j] == ans) ok += go(i, j);
  ans *= 2;
  if (ok < 2 && ans > 0) ans--;
  if (bad) ans = -1;
  printf("%d\n", ans);
  return 0;
}
