var a:array[0..101,0..101] of integer;
f,g:text;
c:char;
n,m,i,j,z,r1,r2,j1,j2,rep,nr,q1,q2:longint;
ok:boolean;
begin
assign(f,'rj.in');reset(f);
assign(g,'rj.out');rewrite(g);
read(f,n,m);
readln(f);
z:=0;
for i:=0 to m+1 do
begin
a[0,i]:=-1;
a[n+1,i]:=-1;
end;
for i:=0 to n+1 do
begin
a[i,0]:=-1;
a[i,m+1]:=-1;
end;
for i:=1 to n do
for j:=1 to m do
begin
read(f,c);
inc(z);
if c='X' then a[i,j]:=-1;
if c=' ' then a[i,j]:=0;
if (c='R') then
begin
a[i,j]:=1;
r1:=i;
r2:=j;
end;
if c='J' then
begin
a[i,j]:=1;
j1:=i;
j2:=j;
end;
if z mod m=0 then readln(f);
end;
close(f);
{for i:=0 to n+1 do
begin
for j:=0 to m+1 do write(g,a[i,j],' ');
writeln(g);
end;
close(g);
end.}
ok:=false;
rep:=1;
repeat
for i:=1 to n do
for j:=1 to m do
begin
if a[i,j]=rep then
begin
if (a[i,j+1]=0)or(a[i,j+1]=rep+1) then
begin
if a[i,j+1]=rep+1 then
begin
q1:=i;
q2:=j+1;
ok:=true;
end;
a[i,j+1]:=rep+1;
inc(nr);
end;
if (a[i,j-1]=0)or(a[i,j-1]=rep+1) then
begin
if a[i,j-1]=rep+1 then
begin
q1:=i;
q2:=j-1;
ok:=true;
end;
a[i,j-1]:=rep+1;
inc(nr);
end;
if (a[i+1,j-1]=0)or(a[i+1,j-1]=rep+1) then
begin
if a[i+1,j-1]=rep+1 then
begin
q1:=i+1;
q2:=j-1;
ok:=true;
end;
a[i+1,j-1]:=rep+1;
inc(nr);
end;
if (a[i+1,j]=0)or(a[i+1,j]=rep+1) then
begin
if a[i+1,j]=rep+1 then
begin
q1:=i+1;
q2:=j;
ok:=true;
end;
a[i+1,j]:=rep+1;
inc(nr);
end;
if (a[i+1,j+1]=0)or(a[i+1,j+1]=rep+1) then
begin
if a[i+1,j+1]=rep+1 then
begin
q1:=i+1;
q2:=j+1;
ok:=true;
end;
a[i+1,j+1]:=rep+1;
inc(nr);
end;
if (a[i-1,j-1]=0)or(a[i-1,j-1]=rep+1) then
begin
if a[i-1,j-1]=rep+1 then
begin
q1:=i-1;
q2:=j-1;
ok:=true;
end;
a[i-1,j-1]:=rep+1;
inc(nr);
end;
if (a[i-1,j]=0)or(a[i-1,j]=rep+1) then
begin
if a[i-1,j]=rep+1 then
begin
q1:=i-1;
q2:=j;
ok:=true;
end;
a[i-1,j]:=rep+1;
inc(nr);
end;
if (a[i-1,j+1]=0)or(a[i-1,j+1]=rep+1) then
begin
if a[i-1,j+1]=rep+1 then
begin
q1:=i-1;
q2:=j+1;
ok:=true;
end;
a[i-1,j+1]:=rep+1;
inc(nr);
end;
end;
if (i=n)and(j=m) then inc(rep);
end;
until ok=true;
write(g,a[q1,q2],' ',q1,' ',q2);
close(g);
end.