#include <bits/stdc++.h>
using namespace std;
int n, m;
char board[2000][2001];
pair<int, int> dp[2000][2000];
bool working[2000][2000];
int maxx[4000000];
int index1 = 1;
pair<int, int> go(int x, int y) {
  pair<int, int> res;
  if (working[x][y]) {
    printf("-1");
    exit(0);
  }
  if (dp[x][y].first != -1) return dp[x][y];
  working[x][y] = true;
  if (board[x][y] == '#') {
    res = make_pair(0, -1);
  } else {
    if (board[x][y] == '>') res = go(x, y + 1);
    if (board[x][y] == '<') res = go(x, y - 1);
    if (board[x][y] == 'v') res = go(x + 1, y);
    if (board[x][y] == '^') res = go(x - 1, y);
    res.first++;
    if (res.first == 1 && res.second == -1) {
      res.second = index1++;
    }
  }
  working[x][y] = false;
  return (dp[x][y] = res);
}
void init1() { return; }
void init2() {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      dp[i][j].first = dp[i][j].second = -1;
      working[i][j] = false;
    }
  }
  return;
}
void input() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", board[i]);
  }
}
int work() {
  int res = 0;
  bool nosharp = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (board[i][j] != '#' && dp[i][j].first == -1) {
        nosharp = false;
        go(i, j);
      }
    }
  }
  if (nosharp) return 0;
  for (int i = 1; i < index1; i++) {
    maxx[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (dp[i][j].second > 0) {
        maxx[dp[i][j].second] = max(maxx[dp[i][j].second], dp[i][j].first);
      }
    }
  }
  int imax = 0;
  int cnt = 0;
  for (int i = 1; i < index1; i++) {
    if (imax < maxx[i]) {
      imax = maxx[i];
      cnt = 0;
    } else if (imax == maxx[i]) {
      cnt = 1;
    }
  }
  if (cnt == 1)
    return imax * 2;
  else
    return imax * 2 - 1;
}
int main() {
  init1();
  input();
  init2();
  printf("%d", work());
}
