#include <bits/stdc++.h>
using namespace std;
int n, m;
char a[2005][2005];
int dp[2005][2005];
inline bool Come(int x, int y, int ix, int iy) {
  if (x < 0 || x >= m || y < 0 || y >= n || x + ix < 0 || x + ix >= m ||
      y + iy < 0 || y + iy >= n)
    return false;
  if (ix == -1) return a[x + ix][y + iy] == '>';
  if (ix == 1) return a[x + ix][y + iy] == '<';
  if (iy == -1) return a[x + ix][y + iy] == 'v';
  if (iy == 1) return a[x + ix][y + iy] == '^';
}
int end(int x, int y) {
  if (dp[x][y] != -1) return 0;
  dp[x][y] = 0;
  int ans = 0;
  for (int ix = -1; ix <= 1; ix++)
    for (int iy = -1; iy <= 1; iy++)
      if ((ix == 0 ^ iy == 0) && Come(x, y, ix, iy))
        ans = max(ans, end(x + ix, y + iy));
  dp[x][y] = ans + 1;
  return dp[x][y];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[j][i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (a[j][i] == '#') end(j, i);
  int Max = 0, tedad = 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (a[j][i] == '#') continue;
      if (dp[j][i] == -1) {
        cout << -1 << endl;
        return 0;
      }
      if (dp[j][i] == Max)
        tedad++;
      else if (dp[j][i] > Max) {
        Max = dp[j][i];
        tedad = 1;
      }
    }
  if (Max == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (tedad > 1)
    cout << 2 * Max << endl;
  else
    cout << 2 * Max - 1 << endl;
  return 0;
}
