#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const int MAXN = 2048;
int n, m;
char grid[MAXN][MAXN];
int in_degree[MAXN][MAXN];
int out_degree[MAXN][MAXN];
int getDx(char ch) {
  if (ch == '^') return -1;
  if (ch == 'v') return 1;
  return 0;
}
int getDy(char ch) {
  if (ch == '<') return -1;
  if (ch == '>') return 1;
  return 0;
}
int visited[MAXN][MAXN];
bool __existCycle(int x, int y, int step) {
  while (grid[x][y] != '#' && !visited[x][y]) {
    visited[x][y] = step;
    int dx = getDx(grid[x][y]), dy = getDy(grid[x][y]);
    x += dx, y += dy;
  }
  return visited[x][y] == step;
}
bool existCycle() {
  memset(visited, 0, sizeof(visited));
  int step = 1;
  for (int x = 1; x < n - 1; x++) {
    for (int y = 1; y < m - 1; y++) {
      if (grid[x][y] != '#' && !visited[x][y]) {
        if (__existCycle(x, y, step++)) return true;
      }
    }
  }
  return false;
}
int pathLen(int x, int y) {
  int len = 0;
  int bx = x, by = y;
  while (grid[x][y] != '#' && !visited[x][y]) {
    int dx = getDx(grid[x][y]), dy = getDy(grid[x][y]);
    x += dx, y += dy;
    len++;
  }
  len += visited[x][y];
  int blen = len;
  x = bx, y = by;
  while (grid[x][y] != '#' && !visited[x][y]) {
    visited[x][y] = len--;
    int dx = getDx(grid[x][y]), dy = getDy(grid[x][y]);
    x += dx, y += dy;
  }
  return blen;
}
void color(int x, int y) {
  while (grid[x][y] != '#') {
    int dx = getDx(grid[x][y]), dy = getDy(grid[x][y]);
    grid[x][y] = '#';
    x += dx, y += dy;
  }
}
int solve() {
  bool isZero = true;
  for (int x = 1; x < n - 1; x++) {
    for (int y = 1; y < m - 1; y++) {
      if (grid[x][y] != '#') isZero = false;
    }
  }
  if (isZero) return 0;
  if (existCycle()) return -1;
  int longestPath = 0, startX, startY;
  memset(visited, 0, sizeof(visited));
  for (int x = 1; x < n - 1; x++) {
    for (int y = 1; y < m - 1; y++) {
      int len = pathLen(x, y);
      if (len > longestPath) {
        startX = x, startY = y;
        longestPath = len;
      }
    }
  }
  color(startX, startY);
  int longestPath2 = longestPath - 1;
  memset(visited, 0, sizeof(visited));
  for (int x = 1; x < n - 1; x++) {
    for (int y = 1; y < m - 1; y++) {
      int len = pathLen(x, y);
      if (len > longestPath2) {
        longestPath2 = len;
      }
    }
  }
  return longestPath + longestPath2;
}
int TestNum;
int main() {
  ios_base::sync_with_stdio(false);
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", grid[i]);
  for (int x = 1; x < n - 1; x++) {
    for (int y = 1; y < m - 1; y++) {
      int dx = getDx(grid[x][y]), dy = getDy(grid[x][y]);
      in_degree[x + dx][y + dy]++;
      out_degree[x][y]++;
    }
  }
  cout << solve() << endl;
}
