#include<bits/stdc++.h>
#define lli long long int
using namespace std;
char str[12][12];
int vis[12][12];
int main()
{
ios::sync_with_stdio(false);
int w,h,p1,p2;
cin>>w>>h;
for(int i=1; i<=w; i++)
{
for(int j=1; j<=h; j++)
{
cin>>str[i][j];
if(str[i][j]=='U' ||str[i][j]=='L' || str[i][j]=='R' || str[i][j]=='D')
{
p1=i;
p2=j;
}
}
}
int ans=1;
vis[p1][p2]=1;
while(1)
{
bool flag=0;
if(str[p1][p2]=='U')
{
if(p1>1 &&(str[p1-1][p2]!='*' ))
{
p1=p1-1;
str[p1][p2]='U';
if(!vis[p1][p2])
ans++;
vis[p1][p2]++;
flag=1;
}
else if(p2<h &&(str[p1][p2+1]!='*' ))
{
p2=p2+1;
str[p1][p2]='R';
if(!vis[p1][p2])
ans++;
vis[p1][p2]++;
flag=1;
}
else if(p1<w && (str[p1+1][p2]!='*' ))
{
p1=p1+1;
str[p1][p2]='D';
if(!vis[p1][p2])
ans++;
vis[p1][p2]++;
flag=1;
}
else if(p2>1 && (str[p1][p2-1]!='*' ))
{
p2=p2-1;
str[p1][p2]='L';
if(!vis[p1][p2])
ans++;
vis[p1][p2]++;
flag=1;
}
}
else if(str[p1][p2]=='R')
{
if(p2<h &&(str[p1][p2+1]!='*' ))
{
p2=p2+1;
str[p1][p2]='R';
if(!vis[p1][p2])
ans++;
vis[p1][p2]++;
flag=1;
}
else if(p1<w && (str[p1+1][p2]!='*'))
{
p1=p1+1;
str[p1][p2]='D';
if(!vis[p1][p2])
ans++;
vis[p1][p2]++;
flag=1;
}
else if(p2>1 && (str[p1][p2-1]!='*' ))
{
p2=p2-1;
str[p1][p2]='L';
if(!vis[p1][p2])
ans++;
vis[p1][p2]++;
flag=1;
}
else if(p1>1 &&(str[p1-1][p2]!='*'))
{
p1=p1-1;
str[p1][p2]='U';
if(!vis[p1][p2])
ans++;
vis[p1][p2]++;
flag=1;
}
}
else if(str[p1][p2]=='D')
{
if(p1<w && (str[p1+1][p2]!='*' ))
{
p1=p1+1;
str[p1][p2]='D';
if(!vis[p1][p2])
ans++;
vis[p1][p2]++;
flag=1;
}
else if(p2>1 && (str[p1][p2-1]!='*'))
{
p2=p2-1;
str[p1][p2]='L';
if(!vis[p1][p2])
ans++;
vis[p1][p2]++;
flag=1;
}
else if(p1>1 &&(str[p1-1][p2]!='*' ))
{
p1=p1-1;
str[p1][p2]='U';
if(!vis[p1][p2])
ans++;
vis[p1][p2]++;
flag=1;
}
else if(p2<h &&(str[p1][p2+1]!='*' ))
{
p2=p2+1;
str[p1][p2]='R';
if(!vis[p1][p2])
ans++;
vis[p1][p2]++;
flag=1;
}
}
else if(str[p1][p2]=='L')
{
if(p2>1 && (str[p1][p2-1]!='*' ))
{
p2=p2-1;
str[p1][p2]='L';
if(!vis[p1][p2])
ans++;
vis[p1][p2]++;
flag=1;
}
else if(p1>1 &&(str[p1-1][p2]!='*' ))
{
p1=p1-1;
str[p1][p2]='U';
if(!vis[p1][p2])
ans++;
vis[p1][p2]++;
flag=1;
}
else if(p2<h &&(str[p1][p2+1]!='*'))
{
p2=p2+1;
str[p1][p2]='R';
if(!vis[p1][p2])
ans++;
vis[p1][p2]++;
flag=1;
}
else if(p1<w && (str[p1+1][p2]!='*'))
{
p1=p1+1;
str[p1][p2]='D';
if(!vis[p1][p2])
ans++;
vis[p1][p2]++;
flag=1;
}
}
//cout<<str[p1][p2]<<endl;
if(vis[p1][p2]>10)
break;
if(!flag)
{
break;
}
}
cout<<ans<<endl;
return 0;
}