type vec = array[-4..101,-4..101] of longint;
type d = record
x, y : longint;
end;
const f = 'rj.in'; g = 'rj.out';
const
dx : array[0..7] of shortint = (-1,1,0,0,1,1,-1,-1);
dy : array[0..7] of shortint = (0,0,-1,1,1,-1,1,-1);
var
ch : char;
min, i, j, n, m : longint;
a, b : vec;
drum : array[0..100001] of d;
sol, ince, sf : d;
function check ( x,y : longint ) : boolean;
begin
if ( x>0) and( x<=n) and ( y>0) and (y<=m) then check := true
else check := false;
end;
procedure lee( var mat : vec; start : d);
var
k, st, dr, ii ,jj : longint;
begin
st := 0;
dr := 1;
drum[st]:=start;
while (st <= dr) do
begin
for k := 0 to 7 do
begin
ii := drum[st].x + dx[k];
jj := drum[st].y + dy[k];
if check(ii,jj) and ( mat[ii,jj] = 0 ) then
begin
drum[dr].x := ii;
drum[dr].y := jj;
mat[ii,jj] := mat[drum[st].x,drum[st].y]+1;
inc ( dr );
end;
end;
inc( st );
end;
end;
begin
assign( input,f ); reset( input );
assign( output,g ); rewrite( output );
readln(n, m);
for i := 1 to n do
begin
for j := 1 to m do
begin
read( ch );
if ch = 'X' then begin a[i,j] := -1; b[i,j] := -1; end;
if ch = 'R' then begin a[i,j] := 0; ince.x := i; ince.y := j; end;
if ch = 'J' then begin b[i,j] := 0; sf.x := i; sf.y := j; end;
if ch = ' ' then begin a[i,j] := 0; b[i,j] := 0; end;
end;
readln;
end;
lee(a,ince);
lee(b,sf);
min := maxlongint;
for i := 1 to n do
for j := 1 to m do begin
if (a[i,j]=b[i,j]) and (a[i,j]>0) and (a[i,j]<min) then begin
min := a[i,j];
sol.x := i;
sol.y := j;
end;
end;
writeln( min+1,' ', sol.x,' ',sol.y );
end.