#include <bits/stdc++.h>
using namespace std;
const int MAX = 2001;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const string dir = "v>^<";
char b[MAX][MAX];
int H, W, done;
inline bool in(int i, int j) { return i >= 0 and i < H and j >= 0 and j < W; }
int dfs(int i, int j, int dep) {
  done++;
  int ret = dep;
  for (int d = (int)(0); d < (int)(4); d++) {
    int ni = i + di[d], nj = j + dj[d];
    if (in(ni, nj) and b[ni][nj] == dir[d])
      ret = max(ret, dfs(ni, nj, dep + 1));
  }
  return ret;
}
int solve() {
  pair<int, int> ans = pair<int, int>(0, 0);
  for (int i = (int)(0); i < (int)(H); i++)
    for (int j = (int)(0); j < (int)(W); j++)
      if (b[i][j] == '#') {
        done++;
        for (int d = (int)(0); d < (int)(4); d++) {
          int ni = i + di[d], nj = j + dj[d];
          if (in(ni, nj) and b[ni][nj] == dir[d]) {
            int t = dfs(ni, nj, 1);
            if (ans.second < t) ans.second = t;
            if (ans.second > ans.first) swap(ans.first, ans.second);
            if (ans.second < t - 1) ans.second = t - 1;
          }
        }
      }
  return done < H * W ? -1 : ans.first + ans.second;
}
void input() {
  cin >> H >> W;
  for (int i = (int)(0); i < (int)(H); i++)
    for (int j = (int)(0); j < (int)(W); j++) cin >> b[i][j];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  input();
  cout << solve() << endl;
  return 0;
}
