#include <bits/stdc++.h>
using namespace std;
const int MXN = 2010;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const int mod = 1000000007;
char mpp[MXN][MXN];
int was[MXN][MXN];
int d[MXN][MXN];
int dfsd(int i, int j) {
  if (was[i][j] == 2) return d[i][j];
  if (was[i][j] == 1) return -INF;
  was[i][j] = 1;
  if (mpp[i][j] == '#') d[i][j] = 0;
  if (mpp[i][j] == '>') d[i][j] = dfsd(i, j + 1) + 1;
  if (mpp[i][j] == '<') d[i][j] = dfsd(i, j - 1) + 1;
  if (mpp[i][j] == '^') d[i][j] = dfsd(i - 1, j) + 1;
  if (mpp[i][j] == 'v') d[i][j] = dfsd(i + 1, j) + 1;
  was[i][j] = 2;
  return d[i][j];
}
bool dfs(int i, int j) {
  if (was[i][j] == 2 && mpp[i][j] != '#') return false;
  if (mpp[i][j] == '#') return true;
  was[i][j] = 1;
  bool q;
  if (mpp[i][j] == '>') q = dfs(i, j + 1);
  if (mpp[i][j] == '<') q = dfs(i, j - 1);
  if (mpp[i][j] == '^') q = dfs(i - 1, j);
  if (mpp[i][j] == 'v') q = dfs(i + 1, j);
  was[i][j] = 2;
  return q;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = (0); i < (n); i++) {
    scanf("%s", mpp[i]);
  }
  int mx = 0;
  for (int i = (0); i < (n); i++) {
    for (int j = (0); j < (m); j++) {
      if (!was[i][j]) {
        int q = dfsd(i, j);
        if (q < 0) {
          printf("-1");
          return 0;
        }
        mx = max(mx, q);
      }
    }
  }
  for (int i = (0); i < (n); i++)
    for (int j = (0); j < (m); j++) was[i][j] = 0;
  if (mx == 0) {
    printf("0");
    return 0;
  }
  int res = 2 * mx - 1, cnt = 0;
  for (int i = (0); i < (n); i++) {
    for (int j = (0); j < (m); j++) {
      if (d[i][j] == mx && dfs(i, j)) cnt++;
    }
  }
  if (cnt < 2)
    cout << res;
  else
    cout << 2 * mx;
}
