#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
int n,m;
char a[15][15];
bool bo[15][15];
int dx[]={-1,0,1,0},dy[]={0,1,0,-1};
char UNdir(int x)
{
    if (x==0) return 'U';
    if (x==1) return 'R';
    if (x==2) return 'D';
    if (x==3) return 'L';
}
int dir(char x)
{
    if (x=='U') return 3;
    if (x=='R') return 0;
    if (x=='D') return 1;
    if (x=='L') return 2;
}
struct node
{
    int d;
    int x[105];
    int y[105];
    int num;
    char fa;
    string ans;
};
bool in(int x,int y)
{
    return (x>=0 && x<n && y>=0 && y<m);
}
void out(node x)
{
    char xx[15][15];
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
                xx[i][j]='.';
        }
    }
    xx[x.d/m][x.d%m]=x.fa;
    for (int i = 0; i < x.num; ++i)
    {
        xx[x.x[i]][x.y[i]]='o';
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
            cout<<xx[i][j];
        }
        cout<<endl;
    }
    cout<<endl;
}
int ans=0,ansd=0;
int main(int argc, char *argv[])
{
    int T;
    cin>>n>>m;
    node xx;xx.num=0;
    xx.ans="";
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0 ; j < m; ++j)
        {
            cin>>a[i][j];
            if (a[i][j]=='o')
            {
                xx.x[xx.num]=i;
                xx.y[xx.num++]=j;
            }
            else if (a[i][j]=='U'||a[i][j]=='L'||a[i][j]=='R'||a[i][j]=='D')
            {
                xx.d=i*m+j;
                xx.fa=a[i][j];
            }
        }
    }
    queue<node> q;
    q.push(xx);
    bool gan=0;
    while (!q.empty())
    {
        node now=q.front();
    
        if (now.num==0)
        {
            cout<<now.ans<<endl;
            break;
        }
        q.pop();
        int x=now.d/m,y=now.d%m;
        memset(bo,0,sizeof(bo));
        bo[x][y]=1;
        for (int i = 0; i < now.num; ++i)
        {
           bo[now.x[i]][now.y[i]]=1;
        }
        int face=dir(now.fa);
        for (int i = face; i < face+3; ++i)
        {
            int ii=i%4;
            int l=1;
            int xx=x+dx[ii],yy=y+dy[ii];
            while (1)
            {
                if (!in(xx,yy)) break;
                if (bo[xx][yy])
                {
                    node go;
                    go.d=xx*m+yy;
                    go.ans=now.ans+UNdir(ii);
                    go.fa=UNdir(ii);
                    go.num=0;
                                        for (int j = 0; j < now.num; ++j)
                    {
                        int xxx=now.x[j],yyy=now.y[j];
                        if (!(xxx==xx&&yyy==yy))
                        {
                            go.x[go.num]=xxx;
                            go.y[go.num++]=yyy;
                        }
                    }
                    q.push(go); 
                    break;
                }
                xx+=dx[ii];
                yy+=dy[ii];
            }
        }
    }
    return 0;
}

Measured memory_bytes: 5952