#include <bits/stdc++.h>
using namespace std;
template <class T>
void CIN(T &a) {
  cin >> a;
}
template <class T>
void CIN(T &a, T &b) {
  cin >> a >> b;
}
template <class T>
void CIN(T &a, T &b, T &c) {
  cin >> a >> b >> c;
}
template <class T>
void CIN(T &a, T &b, T &c, T &d) {
  cin >> a >> b >> c >> d;
}
template <class T>
void PI(T a) {
  cout << a << endl;
}
template <class T>
void PI(T a, T b) {
  cout << a << " " << b << endl;
}
template <class T>
void PIS(T a) {
  cout << a << " ";
}
template <class T>
T abs(T a) {
  return a < 0 ? -a : a;
}
int n, m, max1(0), max2(0), maxn;
char g[2010][2010];
bool v[2010][2010], f;
void dfs(int i, int j, int dep) {
  if (g[i][j] == '#') return;
  maxn = max(maxn, dep + 1);
  if (v[i][j] == 1) {
    f = true;
    return;
  }
  v[i][j] = 1;
  if (g[i - 1][j] == 'v' || g[i - 1][j] == '#') dfs(i - 1, j, dep + 1);
  if (g[i + 1][j] == '^' || g[i + 1][j] == '#') dfs(i + 1, j, dep + 1);
  if (g[i][j + 1] == '<' || g[i][j + 1] == '#') dfs(i, j + 1, dep + 1);
  if (g[i][j - 1] == '>' || g[i][j - 1] == '#') dfs(i, j - 1, dep + 1);
}
bool judge(int i, int j) {
  int ni(i), nj(j);
  if (g[i][j] == 'v') ++ni;
  if (g[i][j] == '^') --ni;
  if (g[i][j] == '<') --nj;
  if (g[i][j] == '>') ++nj;
  if (g[ni][nj] == '#') return true;
  return false;
}
int main() {
  CIN(n, m);
  int i, j;
  for (i = 1; i <= (int)(n); ++i) scanf("%s", g[i] + 1);
  for (i = 1; i <= (int)(n); ++i)
    for (j = 1; j <= (int)(m); ++j)
      if (!v[i][j] && g[i][j] != '#' && judge(i, j)) {
        maxn = 0;
        dfs(i, j, 0);
        if (maxn > max1) {
          max2 = max1;
          max1 = maxn;
        } else
          max2 = max(max2, maxn);
      }
  for (i = 1; i <= (int)(n); ++i)
    for (j = 1; j <= (int)(m); ++j)
      if (!v[i][j] && g[i][j] != '#') f = true;
  if (f) {
    puts("-1");
    return 0;
  }
  int ans = max1 + max(max2, max1 - 1);
  PI(ans);
  return 0;
}
