#include <iostream>
#include <fstream>
#include <cstring>
#include <queue>
using namespace std;
int n,m,ro[101][101],ju[101][101],dl[]= {0,0,-1,1,1,-1,-1,1},dc[]= {1,-1,0,0,1,1,-1,-1},xr,yr,xj,yj,b[101][101];
char ch;
ofstream g("rj.out");
queue<pair<int,int> >coada;
bool ok(int i , int j)
{
if (i<1 || i>n || j<1 || j>m) return false;
else return true;
}
void citire()
{
ifstream f("rj.in");
int i,j;
f>>n>>m; f.get();
for(i=1; i<=n; i++)
{
for(j=1; j<=m; j++)
{
f.get(ch);
if(ch=='X')
ro[i][j]=ju[i][j]=-1;
if(ch=='R')
{
xr=i;
yr=j;
}
if(ch=='J')
{
xj=i;
yj=j;
}
}
f.get(ch);
}
}
void Lee(int x, int y, int h[101][101])
{ int i_urm,j_urm,dir,i,j;
coada.push(make_pair(x,y));
h[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(h[i_urm][j_urm]==0 && ok(i_urm ,j_urm)==true)
{
h[i_urm][j_urm]=h[i][j]+1;
coada.push(make_pair(i_urm,j_urm));
}
}
}
}
int main()
{
int i,j,tmin=101*101,x,y;
citire();
Lee(xr,yr,ro);
Lee(xj,yj,ju);
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
if(ro[i][j]==ju[i][j] && ro[i][j]>0 && ro[i][j]<tmin)
{
tmin=min(ro[i][j],tmin);
x=i;
y=j;
}
g<<tmin<<" "<<x<<" "<<y<<endl;
}