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

/*
ID: temurxo1
PROG: fence
LANG: C++11
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define dout if (debug) cout
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int((x.size())))
#define Coder 404
typedef long double ld;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VPI;
#define REP(i,a,n) for (int i=a;i<n;i++)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x,y) cerr << #x << " = " << x << "  " << #y << " = " << y <<endl
#define PER(i,a,n) for (int i=n-1;i>=a;i--)
const int inf = 1000000404;
const ll MOD = 1000000007ll;
const ld PI = acos(-1.0);
const ll INF = 2000000000000000404ll;
const ld EPS = 1e-9;
template <typename t1, typename t2> inline void upmax(t1 &a, t2 b) { a = max(a, (t1)b); }
template <typename t1, typename t2> inline void upmin(t1 &a, t2 b) { a = min(a, (t1)b); }
template <typename T>inline T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template <typename T>inline T lcm(T a, T b) { return a*(b / gcd(a, b)); }
template <typename T>inline T sqr(T a) { return a*a; }
inline bool pal(string &x) { int n = (int)x.length(); REP(i, 0, n / 2) { if (x[i] != x[n - i - 1]) return 0; }return 1; }
int month[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
#define next kdajglgjk
#define prev sdkjgfdlk
int dx[] = { 1, 0,-1, 0 , 1, 1,-1,-1};
int dy[] = { 0, 1, 0,-1 , 1,-1, 1,-1};
int SQ = 404;
class compare{
public:
    bool operator()(const int a,const int b) const {
        return 1;
        //compare class for PQ
    }
};
template <typename T> using superset = tree<T, null_type, less<T>,rb_tree_tag, tree_order_statistics_node_update>;
template <typename T1,typename T2> using supermap = tree<T1, T2, less<T1>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 5555;
#define debug 1
//**************************************************//
typedef vector<VI> VVI;
VVI lt,rt,up,dn,lt2,rt2,up2,dn2;
char a[N][N];
char b[N][N];
int go(int i,int j) {
    int ret=0;
    while (a[i][j]!='.') {
          //  db2(i,j);
            ret++;
            up[dn[i][j]][j]=up[i][j];
            dn[up[i][j]][j]=dn[i][j];
            lt[i][rt[i][j]]=lt[i][j];
            rt[i][lt[i][j]]=rt[i][j];
            char c=a[i][j];
            a[i][j]='.';
                 if (c=='L') j=lt[i][j];
            else if (c=='R') j=rt[i][j];
            else if (c=='D') i=dn[i][j];
            else i=up[i][j];
    }
    return ret;
}
void solve()
{
    int n,m;
    memset(a,'.',sizeof(a));
    memset(b,'.',sizeof(b));
    cin>>n>>m;
    REP(i,1,n+1)
        REP(j,1,m+1) {
            cin>>a[i][j];
            b[i][j]=a[i][j];
        }
    lt.resize(n+2);
    rt.resize(n+2);
    up.resize(n+2);
    dn.resize(n+2);
    lt2.resize(n+2);
    rt2.resize(n+2);
    up2.resize(n+2);
    dn2.resize(n+2);
    REP(i,0,n+2) {
        lt[i].resize(m+2);
        rt[i].resize(m+2);
        up[i].resize(m+2);
        dn[i].resize(m+2);
        lt2[i].resize(m+2);
        rt2[i].resize(m+2);
        up2[i].resize(m+2);
        dn2[i].resize(m+2);
    }


//    REP(i,0,n+2) {
//        REP(j,0,m+2) dout<<a[i][j]; dout<<endl;
//    }

    REP(i,1,n+1) {
        REP(j,1,m+1) {
            lt2[i][j]=(a[i][j-1]!='.')?(j-1):(lt2[i][j-1]);
            up2[i][j]=(a[i-1][j]!='.')?(i-1):(up2[i-1][j]);
        }
    }
    PER(i,1,n+1) {
        PER(j,1,m+1) {
            rt2[i][j]=(a[i][j+1]!='.')?(j+1):(rt2[i][j+1]);
            dn2[i][j]=(a[i+1][j]!='.')?(i+1):(dn2[i+1][j]);
        }
    }

    //***************
    int ans1=0,ans2=N*N;
//    REP(i,1,n+1) {
//        REP(j,1,m+1) {
//            cout<<setw(2)<<up2[i][j]<<' ';
//        } cout<<endl;
//    }
 //   cout<<go(3,3)<<endl;
   // exit(0);
    REP(x,1,n+1)
        REP(y,1,m+1) {

            REP(i,0,n+2)
                REP(j,0,m+2)  {
                    up[i][j]=up2[i][j];
                    dn[i][j]=dn2[i][j];
                    lt[i][j]=lt2[i][j];
                    rt[i][j]=rt2[i][j];
                    a[i][j]=b[i][j];
                }
            if (a[x][y]!='.') {
            int foo=go(x,y);
            //exit(0);
            upmax(ans1,foo);
            upmin(ans2,foo);
            }
                        }
    cout<<ans1<<' '<<ans2<<endl;
}
//**************************************************//
int main()
{
   // if (debug) freopen("/home/temur/Desktop/in.txt","r",stdin);
	//freopen("fence.in", "r", stdin);
	//freopen("fence.out", "w", stdout);
	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);
	int t = 1;
	//cin>>t;

	while (t--) {
		solve();
	};
	return 0;
}
