#include <bits/stdc++.h>
using namespace std;
string s[2100];
int dp[2100][2100];
bool mark[2100][2100];
inline void next(int &x, int &y) {
  if (s[x][y] == '<')
    y--;
  else if (s[x][y] == '>')
    y++;
  else if (s[x][y] == '^')
    x--;
  else if (s[x][y] == 'v')
    x++;
}
inline int cmp(int x, int y) {
  if (s[x][y] == '#')
    return dp[x][y] = 0;
  else if (dp[x][y] != -1)
    return dp[x][y];
  else if (mark[x][y]) {
    cout << -1 << endl;
    exit(0);
  }
  int xx = x, yy = y;
  mark[x][y] = true;
  next(x, y);
  dp[xx][yy] = cmp(x, y) + 1;
  mark[xx][yy] = false;
  return dp[xx][yy];
}
inline int Solve(int n, int m) {
  memset(dp, -1, sizeof dp);
  int cur = 0, x = 0, y = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (s[i][j] != '#') {
        int now = cmp(i, j);
        if (cur < now) cur = now, x = i, y = j;
      } else
        dp[i][j] = 0;
  while (s[x][y] != '#' and cur > 0) {
    int xx = x, yy = y;
    next(x, y);
    s[xx][yy] = '#';
  }
  return cur;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m, ans1, ans2;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  ans1 = Solve(n, m);
  ans2 = Solve(n, m);
  cout << max(ans1 + ans2, ans1 * 2 - 1) << endl;
}
