fy:array[1..4] of longint=(0,1,0,-1);
var i,j,n,m,max,h:longint;
a:array[1..50,1..50] of char;
visit:array[0..50,0..50] of longint;
sum:array[1..2500] of longint;
procedure ini;
begin
readln(n,m);
for i:=1 to n do begin
for j:=1 to m do read(a[i,j]); readln;
end;
h:=0;
end;
procedure floodfill(i,j:longint);
var k,x,y:longint;
begin
for k:=1 to 4 do begin
x:=i+fx[k]; y:=j+fy[k];
if (x>0) and (x<n+1) and (y>0) and (y<m+1)
then begin
if visit[x,y]=1 then continue;
if a[x,y]='#' then continue;
visit[x,y]:=1; if a[x,y]='R' then inc(sum[h]);
a[x,y]:=chr(h+48);
floodfill(x,y);
end;
end;
end;
//main
begin
ini;
for i:=1 to n do
for j:=1 to m do if (a[i,j]='.') or (a[i,j]='R') then begin
inc(h);
if a[i,j]='R' then sum[h]:=1;
visit[i,j]:=1; a[i,j]:=chr(h+48);
floodfill(i,j);
end;
max:=0;
for i:=1 to h do if sum[h]>max then max:=sum[h];
writeln(max);
end.