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>
using namespace std;
const int maxn = 5005;
const int inf = 5100;
typedef struct a {
  int pos, num;
} per;
short n, m, si[maxn][maxn], ans, ctt;
short tl, tr, tu, td, l[maxn][maxn], r[maxn][maxn], up[maxn][maxn],
    down[maxn][maxn];
void change(int x, int y) {
  tl = l[x][y], tr = r[x][y], tu = up[x][y], td = down[x][y];
  if (tl != inf) r[x][tl] = tr;
  if (tr != inf) l[x][tr] = tl;
  if (td != inf) up[td][y] = tu;
  if (tu != inf) down[tu][y] = td;
}
void go_back(int x, int y, int ttl, int ttr, int ttu, int ttd) {
  if (ttl != inf) r[x][ttl] = y;
  if (ttr != inf) l[x][ttr] = y;
  if (ttd != inf) up[ttd][y] = x;
  if (ttu != inf) down[ttu][y] = x;
}
void print() {
  cout << "TEST\n";
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cout << l[i][j] << ' ';
    }
    cout << "\n";
  }
}
void dfs(int x, int y, int cnt) {
  if (x == inf || y == inf) {
    if (cnt == ans)
      ctt++;
    else if (cnt > ans) {
      ans = cnt;
      ctt = 1;
    }
    return;
  }
  change(x, y);
  int ttl = tl, ttr = tr, ttu = tu, ttd = td;
  if (si[x][y] == 0)
    dfs(up[x][y], y, cnt + 1);
  else if (si[x][y] == 1)
    dfs(down[x][y], y, cnt + 1);
  else if (si[x][y] == 2)
    dfs(x, l[x][y], cnt + 1);
  else
    dfs(x, r[x][y], cnt + 1);
  go_back(x, y, ttl, ttr, ttu, ttd);
  return;
}
int main() {
  cin >> n >> m;
  char tc;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> tc;
      if (tc == '.')
        si[i][j] = -1;
      else if (tc == 'U')
        si[i][j] = 0;
      else if (tc == 'D')
        si[i][j] = 1;
      else if (tc == 'L')
        si[i][j] = 2;
      else
        si[i][j] = 3;
    }
  }
  for (int i = 1; i <= n; ++i) {
    int last = inf;
    for (int j = 1; j <= m; ++j) {
      if (si[i][j] != -1) {
        l[i][j] = last;
        last = j;
      }
    }
    last = inf;
    for (int j = m; j >= 1; --j) {
      if (si[i][j] != -1) {
        r[i][j] = last;
        last = j;
      }
    }
  }
  for (int j = 1; j <= m; ++j) {
    int last = inf;
    for (int i = 1; i <= n; ++i) {
      if (si[i][j] != -1) {
        up[i][j] = last;
        last = i;
      }
    }
    last = inf;
    for (int i = n; i >= 1; --i) {
      if (si[i][j] != -1) {
        down[i][j] = last;
        last = i;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (si[i][j] != -1) dfs(i, j, 0);
    }
  }
  cout << ans << ' ' << ctt;
  return 0;
}
