#include <bits/stdc++.h>
using namespace std;
int lsone(int n) { return (n & -n); }
void mult(long long int a[25][25], long long int b[25][25],
          long long int c[25][25], int m, int n, int p) {
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= p; j++) {
      c[i][j] = 0;
      for (int k = 1; k <= n; k++) {
        c[i][j] += (a[i][k] * b[k][j]) % 1000000007;
        c[i][j] %= 1000000007;
      }
    }
  }
}
void mat_pow(long long int a[25][25], long long int c[25][25], int n,
             long long int p) {
  if (p == 0) {
    for (int i = 1; i <= n; i++) c[i][i] = 1;
  } else if (p == 1) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) c[i][j] = a[i][j];
    }
  } else {
    long long int d[25][25];
    mat_pow(a, d, n, p / 2);
    if (p % 2) {
      long long int e[25][25];
      mult(d, d, e, n, n, n);
      mult(e, a, c, n, n, n);
    } else {
      mult(d, d, c, n, n, n);
    }
  }
}
long long int pow1(long long int a, long long int b) {
  if (b == 0)
    return 1ll;
  else if (b == 1)
    return a;
  else {
    long long int x = pow1(a, b / 2);
    x *= x;
    x %= 1000000007;
    if (b % 2) {
      x *= a;
      x %= 1000000007;
    }
    return x;
  }
}
int n, m, moves[2100][2100], vis[2100][2100], cyc = 0;
pair<int, pair<int, int> > dest[2100][2100];
char grid[2100][2100];
vector<pair<int, pair<int, int> > > ans;
void dfs(int x, int y) {
  vector<pair<int, int> > v;
  int a = x, b = y;
  while (grid[x][y] != '#' and moves[x][y] == 0) {
    if (vis[x][y]) {
      cyc = 1;
      return;
    }
    v.push_back(make_pair(x, y));
    vis[x][y] = 1;
    if (grid[x][y] == '^')
      x--;
    else if (grid[x][y] == 'v')
      x++;
    else if (grid[x][y] == '<')
      y--;
    else
      y++;
  }
  for (int i = v.size() - 1; i >= 0; i--) {
    x = v[i].first, y = v[i].second;
    if (grid[x][y] == '^') {
      if (grid[x - 1][y] != '#') {
        moves[x][y] = 1 + moves[x - 1][y];
        dest[x][y] = dest[x - 1][y];
      } else {
        moves[x][y] = 1;
        dest[x][y] = make_pair(1, make_pair(x - 1, y));
      }
    } else if (grid[x][y] == 'v') {
      if (grid[x + 1][y] != '#') {
        moves[x][y] = 1 + moves[x + 1][y];
        dest[x][y] = dest[x + 1][y];
      } else {
        moves[x][y] = 1;
        dest[x][y] = make_pair(2, make_pair(x + 1, y));
      }
    } else if (grid[x][y] == '<') {
      if (grid[x][y - 1] != '#') {
        moves[x][y] = 1 + moves[x][y - 1];
        dest[x][y] = dest[x][y - 1];
      } else {
        moves[x][y] = 1;
        dest[x][y] = make_pair(3, make_pair(x, y - 1));
      }
    } else {
      if (grid[x][y + 1] != '#') {
        moves[x][y] = 1 + moves[x][y + 1];
        dest[x][y] = dest[x][y + 1];
      } else {
        moves[x][y] = 1;
        dest[x][y] = make_pair(4, make_pair(x, y + 1));
      }
    }
    ans.push_back(make_pair(moves[x][y], make_pair(x, y)));
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) cin >> grid[i][j];
  }
  for (int i = 1; i <= n and !cyc; i++) {
    for (int j = 1; j <= m; j++) {
      if (grid[i][j] != '#' and moves[i][j] == 0) {
        dfs(i, j);
        if (cyc) break;
      }
    }
  }
  if (cyc) {
    cout << -1 << "\n";
    return 0;
  }
  if (ans.size() <= 1) {
    cout << 0 << "\n";
    return 0;
  }
  sort(ans.begin(), ans.end());
  int l = ans.size();
  long long int ans1 = ans[l - 1].first, flag = 0;
  pair<int, pair<int, int> > temp =
      dest[ans[l - 1].second.first][ans[l - 1].second.second];
  for (int i = l - 2; i >= 0; i--) {
    int x = ans[i].second.first, y = ans[i].second.second;
    if (dest[x][y] != temp or (moves[x][y] != ans1)) {
      ans1 += ans[i].first;
      flag = 1;
      break;
    }
  }
  if (!flag) {
    cout << 0 << "\n";
  } else
    cout << ans1 << "\n";
  return 0;
}
