#include <bits/stdc++.h>
int nex[5000000];
int st[5000000];
bool in[5000000];
bool out[5000000];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  memset(nex, -1, sizeof(nex));
  memset(in, false, sizeof(in));
  memset(out, false, sizeof(out));
  char ch;
  getchar();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%c", &ch);
      if (ch != '#') out[i * (m + 2) + j + 1] = true;
      if (ch == '^') {
        nex[i * (m + 2) + j + 1] = (i - 1) * (m + 2) + j + 1;
        in[(i - 1) * (m + 2) + j + 1] = true;
      }
      if (ch == 'v') {
        nex[i * (m + 2) + j + 1] = (i + 1) * (m + 2) + j + 1;
        in[(i + 1) * (m + 2) + j + 1] = true;
      }
      if (ch == '<') {
        nex[i * (m + 2) + j + 1] = i * (m + 2) + j;
        in[i * (m + 2) + j] = true;
      }
      if (ch == '>') {
        nex[i * (m + 2) + j + 1] = i * (m + 2) + j + 2;
        in[i * (m + 2) + j + 2] = true;
      }
    }
    getchar();
  }
  int tot = 0;
  bool flag = true;
  int ans = 0;
  int anspre = -1;
  for (int i = 0; i <= (n + 2) * (m + 2); i++) {
    if (in[i] && out[i] && i == nex[nex[i]]) {
      flag = false;
      break;
    }
    if (!in[i] && out[i]) {
      int j = i;
      int step = 0;
      int pre = -1;
      while (nex[j] != -1) {
        pre = j;
        j = nex[j];
        step++;
      }
      if (step > ans) {
        ans = step;
        anspre = pre;
        tot = 1;
      } else if (step == ans && anspre != pre) {
        tot++;
      }
    }
  }
  if (!flag)
    printf("-1");
  else if (tot >= 2)
    printf("%d", ans * 2);
  else if (tot == 1)
    printf("%d", ans * 2 - 1);
  else if (tot == 0)
    printf("0");
  return 0;
}
