#include <fstream>
#include <cstring>
#include <queue>
using namespace std;
ifstream fin("rj.in");
ofstream cout("rj.out");
int RO[102][102],JU[102][102],N,M,xr,yr,xj,yj;
char ch;
queue < pair<int,int> > coada;
int dl[]={0,0,-1,1,-1,1,1,-1}, dc[]={-1,1,0,0,1,1,-1,-1},tmin,xmin,ymin;
void citeste()
{
fin>>N>>M;fin.get(ch);
for(int i=1;i<=N;i++)
{
for(int j=1;j<=M;j++)
{fin.get(ch);
if(ch=='R') {
xr=i; yr=j;
}
else if(ch=='J')
{
xj=i; yj=j;
}
else if(ch=='X')
RO[i][j]=JU[i][j]=-1;
}
fin.get();
}
}
bool ok(int i, int j)
{
if(i<1 || i>N || j<1 || j>M ) return false;
return true;
}
void Lee(int x,int y, int B[102][102])
{
int i,j,i_urm,j_urm,dir;
memset(B,0,sizeof(B));
while(!coada.empty()) coada.pop();
coada.push(make_pair(x,y));
B[x][y]=1;
while(!coada.empty())
{
i=coada.front().first;
j=coada.front().second;
coada.pop();
for(dir=0;dir<8;dir++)
{
i_urm=i+dl[dir] ;
j_urm=j+dc[dir];
if(ok(i_urm,j_urm) && B[i_urm][j_urm]==0)
{
coada.push(make_pair(i_urm,j_urm));
B[i_urm][j_urm]=B[i][j]+1;
}
}
}
}
void drum_minim()
{
tmin=101*101;
xmin=ymin=-1;
for(int i=1;i<=N;i++)
for(int j=1;j<=M;j++)
if(RO[i][j]==JU[i][j])
if(RO[i][j]<tmin && RO[i][j]>0)
{
tmin=RO[i][j]; xmin=i; ymin=j;
}
cout<<tmin<<" "<<xmin<<" "<<ymin<<endl;
}
int main()
{
citeste();
Lee(xr,yr,RO); Lee(xj,yj,JU); drum_minim();
}