#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265359;
int get(int x, int y, int dir) { return x * 2050 + y + dir * 5000000; }
int n, m;
char f[2050][2050];
int color[2050][2050];
int len[2050][2050];
int id[2050][2050];
int maxLen = 0;
int maxId;
bool inf;
bool x2;
int dir[256];
void dfs(int X, int Y) {
  stack<pair<int, int>, vector<pair<int, int> > > st;
  int x, y, nx, ny;
  st.push(make_pair(X, Y));
  while (!st.empty()) {
    x = st.top().first;
    y = st.top().second;
    color[x][y] = 1;
    nx, ny;
    if (f[x][y] == '#') {
      id[x][y] = get(x, y, 0);
      color[x][y] = 2;
      st.pop();
      continue;
    } else if (f[x][y] == '>')
      nx = x, ny = y + 1;
    else if (f[x][y] == '<')
      nx = x, ny = y - 1;
    else if (f[x][y] == '^')
      nx = x - 1, ny = y;
    else
      nx = x + 1, ny = y;
    if (color[nx][ny] == 1) {
      inf = true;
      return;
    } else if (color[nx][ny] == 2) {
      len[x][y] = len[nx][ny] + 1;
      id[x][y] = f[nx][ny] == '#' ? get(nx, ny, dir[f[x][y]]) : id[nx][ny];
      if (len[x][y] > maxLen)
        maxLen = len[x][y], maxId = id[x][y], x2 = false;
      else if (len[x][y] == maxLen && maxId != id[x][y])
        x2 = true;
      color[x][y] = 2;
      st.pop();
    } else
      st.push(make_pair(nx, ny));
  }
}
int main() {
  dir['>'] = 1;
  dir['<'] = 2;
  dir['^'] = 3;
  dir['v'] = 4;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", f[i]);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (!color[i][j]) {
        dfs(i, j);
        if (inf) {
          puts("-1");
          return 0;
        }
      }
  if (!maxLen)
    puts("0");
  else if (x2)
    printf("%d", maxLen * 2);
  else
    printf("%d", maxLen * 2 - 1);
  return 0;
}
