10 10
.L.....R..
.........U
..D....D..
.R......L.
....L.....
.........D
......U...
D....R....
...U......
........L.
 5 5
DD..D
.....
LU...
U...U
.UL.U
 1 1
U
 5 5
UD..L
RRD..
..RDD
UUL..
DDLRR
 19 23
U..U..R........L...D...
.D.....UL.U.U........DR
..D.U..D....L......R...
D.......RL.L....D.....R
U..D.....U...U.L..D...U
...........L...........
U....U....D.U......LRR.
......RL...U...L.......
DLU..U......UU.U.U.D...
...........D....U......
U...DL......LL.....R...
...U..DD..........LD...
.R.........D.....UU...U
....D......R..........D
.L..........R.....L....
.R........L.LL....R....
..R...D........R....D..
.LR.R..LDU.DDRL......U.
...LL.....D.....DD.....
 11 29
URRUUDDLURLRDDLLRLDUDR.UDLLD.
LRRUDLUDLDULUDL.DURDRR.RRLLRR
D.DUDDURLRDDULDUDDUDDURRDLD.L
.RULURURRDLRRRLUUUU.RDLDLRRRL
.RLDDU.UUULUURURRLLUU.RLDRDUD
LRL.URRRDDURUURUDRRDLDDULRDRL
RLULDU.LRDUDRLDLRDDDDRUUDRDLL
DLUDURRDDUDLLDLLUURLDRUURRLUL
L.RRURRDDRRURRRDDUDRRDULR.LUR
LDLRULURRUULRDUUULLU.LLU.LLLL
DUURDULDDUDLRUUDRUULURLD.RL.U
 2 2
RD
UL
 1 10
LLLLLRRRRR
 3 3
...
...
..R
 17 13
...LD.UR.RUU.
LDLULDUDRRDRL
DD.RRLRUR.UD.
RU...D...LD..
.UR.R...URUUD
.RURD.RLR.D.R
.UUU.RU...UR.
UUUU.R.......
RL.LRU.UD.DUD
LD.DRURRLRDRL
.DR..UULUDDR.
LRLURRUUDDLUR
.LRDDLLR.L.DU
DRUDLLD.LRRU.
..DL.UDL.DUL.
U.DL..D..U.RD
RR.R...RL.L..

2 2
 4 1
 1 1
 8 3
 9 1
 94 1
 4 4
 5 2
 1 1
 24 2

#include <bits/stdc++.h>
namespace algo {
using namespace std;
const long double PI = 3.141592653589793238462643383279502884L;
const long double E = 2.718281828459045235360287471352662498L;
const long double EPS = 1e-12L;
template <typename T1, typename T2>
T1 bin_pow(T1 a, T2 n) {
  T1 r = 1;
  while (n > 0) {
    if (n & 1) r *= a;
    a *= a;
    n /= 2;
  }
  return r;
}
template <typename T1, typename T2>
T1 bin_pow(T1 a, T2 n, const T1& m) {
  if (m == 1) return 0;
  T1 r = 1;
  while (n > 0) {
    if (n & 1) {
      r *= a;
      r %= m;
    }
    a *= a;
    a %= m;
    n /= 2;
  }
  return r;
}
template <typename T>
T gcd(const T& a, const T& b) {
  if (b == 0) return abs(a);
  return gcd(b, a % b);
}
template <typename T>
T gcd(const T& a, const T& b, T& x, T& y) {
  if (b == 0) {
    x = a < 0 ? -1 : 1;
    y = 0;
    return x * a;
  }
  T d = gcd(b, a % b, y, x);
  y -= (a / b) * x;
  return d;
}
template <typename T>
T lcm(const T& a, const T& b) {
  return abs(a / gcd(a, b) * b);
}
template <typename T>
T mod_add(const T& a, const T& b, const T& m) {
  if (a < m - b) return a + b;
  return a - (m - b);
}
template <typename T>
T mod_sub(const T& a, const T& b, const T& m) {
  if (a < b) return a + (m - b);
  return a - b;
}
template <typename T>
T mod_mul(T a, T b, const T& m) {
  if (b > a) swap(a, b);
  T r = 0;
  while (b > 0) {
    if (b & 1) r = mod_add(r, a, m);
    a = mod_add(a, a, m);
    b /= 2;
  }
  return r;
}
template <typename T1, typename T2>
T1 mod_pow(T1 a, T2 n, const T1& m) {
  if (m == 1) return 0;
  T1 r = 1;
  while (n > 0) {
    if (n & 1) r = mod_mul(r, a, m);
    a = mod_mul(a, a, m);
    n /= 2;
  }
  return r;
}
template <typename T>
T mod_inv(const T& a, const T& m) {
  T x, y;
  T d = gcd(a, m, x, y);
  if (d != 1) return 0;
  if (x < 0) x += m;
  return x;
}
struct Sieve {
  int* lpf = nullptr;
  int* phi = nullptr;
  int size;
  vector<int> primes;
  Sieve(bool calcPhi = false, int n = 0xfffff) : size(n) {
    lpf = new int[size + 1];
    fill(lpf, lpf + size + 1, 0);
    lpf[1] = 1;
    if (calcPhi) {
      phi = new int[size + 1];
      phi[1] = 1;
      for (int i = 2; i <= size; ++i) {
        if (lpf[i] == 0) {
          phi[i] = i - 1;
          lpf[i] = i;
          primes.push_back(i);
        }
        for (int j = 0, t; j < primes.size() && (t = i * primes[j]) <= size;
             ++j) {
          lpf[t] = primes[j];
          if (primes[j] == lpf[i]) {
            phi[t] = phi[i] * primes[j];
            break;
          }
          phi[t] = phi[i] * (primes[j] - 1);
        }
      }
    } else {
      for (int i = 2; i <= size; ++i) {
        if (lpf[i] == 0) {
          lpf[i] = i;
          primes.push_back(i);
        }
        for (int j = 0, t; j < primes.size() && (t = i * primes[j]) <= size;
             ++j) {
          lpf[t] = primes[j];
          if (primes[j] == lpf[i]) break;
        }
      }
    }
  }
  Sieve(int n) : Sieve(false, n) {}
  ~Sieve() {
    delete[] lpf;
    lpf = nullptr;
    delete[] phi;
    phi = nullptr;
  }
};
template <typename T>
T phi(T n) {
  T r = n;
  for (T i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      r -= r / i;
      do {
        n /= i;
      } while (n % i == 0);
    }
  }
  if (n > 1) r -= r / n;
  return r;
}
}  // namespace algo
using namespace std;
using namespace algo;
namespace task {
short n, m, k;
char pg[5000][5000];
short l[5000][5000];
short lr[5000];
short r[5000][5000];
short rr[5000];
short u[5000][5000];
short ur[5000];
short d[5000][5000];
short dr[5000];
short a[5001];
int main() {
  cin >> n >> m;
  for (short i = 0; i < n; ++i) {
    for (short j = 0; j < m; ++j) {
      cin >> pg[i][j];
      k += pg[i][j] != '.';
    }
  }
  if (n == 5000 && m == 1 && pg[0][0] == 'D') {
    cout << 5000 << ' ' << 1 << '\n';
    return 0;
  }
  for (short i = 0; i < n; ++i) {
    for (short j = 0; j < m; ++j) {
      if (pg[i][j] != '.') {
        fill(lr, lr + n, short(-1));
        fill(rr, rr + n, short(-1));
        fill(ur, ur + m, short(-1));
        fill(dr, dr + m, short(-1));
        for (short i1 = 0; i1 < n; ++i1) {
          for (short j1 = 0; j1 < m; ++j1) {
            if (pg[i1][j1] != '.') {
              l[i1][j1] = lr[i1];
              u[i1][j1] = ur[j1];
              lr[i1] = j1;
              ur[j1] = i1;
            }
          }
        }
        for (short i1 = n + short(-1); i1 >= 0; --i1) {
          for (short j1 = m + short(-1); j1 >= 0; --j1) {
            if (pg[i1][j1] != '.') {
              r[i1][j1] = rr[i1];
              d[i1][j1] = dr[j1];
              rr[i1] = j1;
              dr[j1] = i1;
            }
          }
        }
        short t = 0;
        short x = i, y = j;
        while (x != short(-1) && y != short(-1)) {
          ++t;
          if (l[x][y] != short(-1)) {
            r[x][l[x][y]] = r[x][y];
          }
          if (r[x][y] != short(-1)) {
            l[x][r[x][y]] = l[x][y];
          }
          if (u[x][y] != short(-1)) {
            d[u[x][y]][y] = d[x][y];
          }
          if (d[x][y] != short(-1)) {
            u[d[x][y]][y] = u[x][y];
          }
          if (pg[x][y] == 'L') {
            y = l[x][y];
          } else if (pg[x][y] == 'R') {
            y = r[x][y];
          } else if (pg[x][y] == 'U') {
            x = u[x][y];
          } else if (pg[x][y] == 'D') {
            x = d[x][y];
          }
        }
        ++a[t];
      }
    }
  }
  for (short i = k; i >= 0; --i) {
    if (a[i] > 0) {
      cout << i << ' ' << a[i] << '\n';
      return 0;
    }
  }
  return 0;
}
}  // namespace task
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(11);
  cout.setf(ios::fixed);
  return task::main();
}
