#include <bits/stdc++.h>
using namespace std;
const int N = (int)(2e3 + 50);
int n, m;
int d[N][N];
char f[N][N];
int dx[N], dy[N];
bool has_cycle = false;
bool used[N][N];
int dfs(int i, int j) {
  if (used[i][j]) {
    cout << -1;
    exit(0);
  }
  if (d[i][j] != -1) return d[i][j];
  used[i][j] = true;
  d[i][j] = 1 + dfs(i + dx[f[i][j]], j + dy[f[i][j]]);
  used[i][j] = false;
  return d[i][j];
}
void dfs1(int i, int j) {
  if (d[i][j] == 0) return;
  used[i][j] = true;
  dfs1(i + dx[f[i][j]], j + dy[f[i][j]]);
}
bool dfs2(int i, int j, int t) {
  if (d[i][j] == 0) return true;
  if (used[i][j]) {
    if (d[i][j] == t)
      return false;
    else
      return true;
  } else {
    return dfs2(i + dx[f[i][j]], j + dy[f[i][j]], t - 1);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  dy['>'] = 1;
  dy['<'] = -1;
  dx['v'] = 1;
  dx['^'] = -1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> f[i][j];
      if (f[i][j] != '#') d[i][j] = -1;
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (d[i][j] == -1) dfs(i, j);
    }
  }
  int ans = 0;
  int md = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      md = max(md, d[i][j]);
    }
  }
  if (md == 0) {
    cout << 0;
    return 0;
  }
  bool first = true;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (d[i][j] == md) {
        if (first) {
          ans = 2 * md - 1;
          first = false;
          dfs1(i, j);
        } else {
          if (dfs2(i, j, md)) {
            cout << 2 * md;
            return 0;
          }
        }
      }
    }
  }
  cout << ans;
  return 0;
}
