#include <fstream>
#include <cstring>
#include <queue>
using namespace std;
ifstream fin("rj.in");
ofstream fout("rj.out");
int RO[102][102],JU[102][102],N,M,xr,yr,xj,yj;
char A[102][102];
queue < pair<int,int> > coada;
int dl[]={0,1,1,1,0,-1,-1,-1},dc[]={1,1,0,-1,-1,-1,0,1},tmin,xmin,ymin;
void citeste()
{
fin>>N>>M;fin.get();
for(int i=1;i<=N;i++)
{
for(int j=1;j<=M;j++)
{fin.get(A[i][j]);
if(A[i][j]=='R') {
xr=i; yr=j;
}
else if(A[i][j]=='J')
{
xj=i; yj=j;
}
}
fin.get();
}
}
bool ok(int i, int j)
{
if(i<1 || i>N || j<1 || j>M || A[i][j]=='X') 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] && RO[i][j]<tmin && RO[i][j]!=0)
{
tmin=RO[i][j]; xmin=i; ymin=j;
}
fout<<tmin<<" "<<xmin<<" "<<ymin<<endl;
}
int main()
{
citeste();
Lee(xr,yr,RO); Lee(xj,yj,JU); drum_minim();
}