#include <bits/stdc++.h>
using namespace std;
int visited = 0, n, m, d0 = 0, d1 = 0, point;
string x[2000];
int dfs(int i, int j, char c) {
  if (i < 0 || i >= n || j < 0 || j >= m || x[i][j] != c) return 0;
  visited++;
  int d = 0;
  d = max(d, dfs(i, j - 1, '>'));
  d = max(d, dfs(i, j + 1, '<'));
  d = max(d, dfs(i - 1, j, 'v'));
  d = max(d, dfs(i + 1, j, '^'));
  return d + 1;
};
void update(int d) {
  if (d > d0)
    d1 = d0, d0 = d;
  else if (d > d1)
    d1 = d;
};
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> x[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (x[i][j] == '#') {
        visited++;
        update(dfs(i, j - 1, '>'));
        update(dfs(i, j + 1, '<'));
        update(dfs(i - 1, j, 'v'));
        update(dfs(i + 1, j, '^'));
      };
  cout << (visited < n * m ? -1
           : d0 == d1      ? d0 + d1
                           : d0 + max(d0 - 1, d1))
       << endl;
  return 0;
};
