#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
ofstream out("rj.out");
#define Nmax 104
const int dx[]={-1,-1,0,1,1,1,0,-1};
const int dy[]={0,1,1,1,0,-1,-1,-1};
char a[Nmax][Nmax];
int xr,yr,xj,yj,romeo[Nmax][Nmax],julieta[Nmax][Nmax];
int n,m;
void citire()
{
ifstream in("rj.in");
in>>n>>m;
in.get();
char sir[Nmax];
int i,j,dim;
for(i=1;i<=n;i++)
{
in.getline(sir,100,'\n');
dim=strlen(sir);
for(j=0;j<dim;j++)
{
if(sir[j]=='R')
{
xr=i;
yr=j+1;
romeo[i][j+1]=1;
}
if(sir[j]=='J')
{
xj=i;
yj=j+1;
julieta[i][j+1]=1;
}
if(sir[j]=='X')
{
romeo[i][j+1]=-1;
julieta[i][j+1]=-1;
}
}
}
in.close();
}
int bune(int i, int j)
{
return (i>=1 and i<=n and j>=1 and j<=m);
}
void lee(int mat[][Nmax],int xi, int yi)
{
int x[Nmax*Nmax],y[Nmax*Nmax],ii,jj,k,pi,ps;
x[0]=xi;
y[0]=yi;
pi=0; ps=0;
while(pi<=ps)
{
for(k=0;k<8;k++)
{
ii=x[pi]+dx[k];
jj=y[pi]+dy[k];
if(bune(ii,jj))
if(mat[ii][jj]==0)
{
mat[ii][jj]=mat[x[pi]][y[pi]]+1;
ps++;
x[ps]=ii;
y[ps]=jj;
}
}
pi++;
}
}
void traseu_minim()
{
int i,j,minn=9999,pi,pf;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
if(romeo[i][j]==julieta[i][j] && romeo[i][j]!=-1)
if(romeo[i][j]<minn && romeo[i][j]>0)
{
minn=romeo[i][j];
pi=i;
pf=j;
}
out<<minn<<" "<<pi<<" "<<pf;
}
int main()
{
citire();
lee(romeo,xr,yr);
lee(julieta,xj,yj);
traseu_minim();
out.close();
return 0;
}