#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int n,m;
char a[1010][1010];
bool ok[1010][1010];
int sum;
int wyx(int x,int y){
if(ok[x][y]==false){
sum++;
ok[x][y]=true;
}
if(a[x][y]=='r'){
y++;
}else if(a[x][y]=='d'){
x++;
}else if(a[x][y]=='l'){
y--;
}else if(a[x][y]=='u'){
x--;
}else if(a[x][y]=='o'){
return sum;
}else{
return 0;
}
return wyx(x,y);
}
int main(){
int ans=0;
char c;
scanf("%d%d",&n,&m);
scanf("%c",&c);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
scanf("%c",&a[i][j]);
}scanf("%c",&c);
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(ok[i][j]==false){
ans+=wyx(i,j);
sum=0;
}
}
}
printf("%d",ans);
return 0;
}