#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int n, m, dist[N][N], circle;
int way[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};
char str[N][N];
set<pair<int, int> > myset[2];
int id(char ch) {
  if (ch == '>') return 0;
  if (ch == '<') return 1;
  if (ch == 'v') return 2;
  if (ch == '^') return 3;
}
int dfs(int x, int y) {
  if (dist[x][y] >= 0) return dist[x][y];
  if (dist[x][y] == -2) {
    circle = 1;
    return 0;
  }
  if (str[x][y] == '#') {
    return 0;
  }
  if (circle) return 0;
  dist[x][y] = -2;
  int ret = 0;
  return dist[x][y] =
             1 + dfs(x + way[id(str[x][y])][0], y + way[id(str[x][y])][1]);
}
int main() {
  while (scanf("%d %d", &n, &m) != EOF) {
    for (int i = 0; i < n; i++) {
      scanf("%s", str[i]);
    }
    memset(dist, -1, sizeof(dist));
    circle = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (dist[i][j] == -1 && str[i][j] != '#') {
          dist[i][j] = dfs(i, j);
        }
      }
    }
    if (circle) {
      puts("-1");
      continue;
    }
    int d = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        d = max(d, dist[i][j]);
      }
    }
    if (d == 0) {
      puts("0");
      continue;
    }
    myset[0].clear();
    myset[1].clear();
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (dist[i][j] == d) {
          myset[0].insert(make_pair(i, j));
        }
      }
    }
    if (d == 1) {
      if (myset[0].size() > 1) {
        puts("2");
      } else
        puts("0");
      continue;
    }
    for (int i = 0; i < d - 1; i++) {
      set<pair<int, int> >::iterator it = myset[i & 1].begin();
      myset[(i + 1) & 1].clear();
      for (; it != myset[i & 1].end(); it++) {
        int x = it->first, y = it->second;
        myset[(i + 1) & 1].insert(
            make_pair(x + way[id(str[x][y])][0], y + way[id(str[x][y])][1]));
      }
    }
    if (myset[(d + 1) & 1].size() > 1) {
      cout << 2 * d << endl;
    } else
      cout << 2 * d - 1 << endl;
  }
  return 0;
}
