{$M 65520,0,655360}
var n,m,i,j,v1,v2,ni,nf:integer;
a:array[0..101,0..101]of integer;
c:char;
f,g:text;
k,xf,yf,p,u,v:integer;
q:boolean;
procedure lee(i,j:integer);
begin
if a[i,j+1]=0 then a[i,j+1]:=k
else if a[i,j+1]=k then begin q:=true; xf:=i; yf:=j+1; end;
if a[i,j-1]=0 then a[i,j-1]:=k
else if a[i,j-1]=k then begin q:=true; xf:=i; yf:=j-1; end;
if a[i+1,j]=0 then a[i+1,j]:=k
else if a[i+1,j]=k then begin q:=true; xf:=i+1; yf:=j; end;
if a[i-1,j]=0 then a[i-1,j]:=k
else if a[i-1,j]=k then begin q:=true; xf:=i-1; yf:=j; end;
if a[i+1,j+1]=0 then a[i+1,j+1]:=k
else if a[i+1,j+1]=k then begin q:=true; xf:=i+1; yf:=j+1; end;
if a[i-1,j+1]=0 then a[i-1,j+1]:=k
else if a[i-1,j+1]=k then begin q:=true; xf:=i-1; yf:=j+1; end;
if a[i-1,j-1]=0 then a[i-1,j-1]:=k
else if a[i-1,j-1]=k then begin q:=true; xf:=i-1; yf:=j-1; end;
if a[i+1,j-1]=0 then a[i+1,j-1]:=k
else if a[i+1,j-1]=k then begin q:=true; xf:=i+1; yf:=j-1; end;
end;
begin
assign(f,'rj.in');
reset(f);
readln(f,n,m);
{for i:=1 to n do
begin
for j:=1 to m do
begin
read(f,c);
case c of
'X': a[i,j]:=-1;
' ': a[i,j]:=0;
'R': a[i,j]:=1;
'J': a[i,j]:=1;
end;
end;
readln(f);
end;}
i:=0;
while Not eof(f) do
begin
i:=i+1; j:=0;
while Not eoln(f) Do
begin
read(f,c);
j:=j+1;
case c of
'X': a[i,j]:=-1;
' ': a[i,j]:=0;
'R': a[i,j]:=1;
'J': a[i,j]:=1;
end;
end;
Readln(f);
end;
for i:=1 to n do
begin
for j:=1 to m do
write(a[i,j],' ');
writeln;
end;
for i:=0 to n+1 do
begin
a[i,0]:=-1;
a[i,m+1]:=-1;
end;
for j:=0 to m+1 do
begin
a[0,j]:=-1;
a[n+1,j]:=-1;
end;
k:=1;
q:=false;
while q=false do
begin
k:=k+1;
for i:=1 to n do
for j:=1 to m do
if a[i,j]=k-1 then lee(i,j);
end;
assign(g,'rj.out');
rewrite(g);
if q then
writeln(g,k,' ',xf,' ',yf);
close(g);
end.