#include <bits/stdc++.h>
#define N 1002
using namespace std;
ifstream fin("rj.in");
ofstream fout("rj.out");
int n,m, a[N][N],r[N][N],ju[N][N],rx,ry,jx,jy,solx,soly;
char s[N];
queue < pair <int , int> > coada;
int di[] = {0, 0,1,-1,1,-1, 1,-1};
int dj[] = {1,-1,0, 0,1,-1,-1, 1};
void Read()
{
int i, j;
char x;
fin >> n >> m;
for(i=0 ;i<=n; i++)
{
fin.getline(s+1,m+1);
for(j=1; j<=m; j++)
if(s[j] == 'X') a[i][j] = -1;
else if(s[j] == 'R') rx = i, ry = j;
else if(s[j] == 'J') jx = i, jy = j;
}
}
bool OK(int i, int j)
{
if(i < 1 || j < 1 || i > n || j > m)
return 0;
if(a[i][j] == -1)
return 0;
return 1;
}
void Lee(int x, int y, int l[N][N])
{
int i,j,ii,jj;
l[x][y] = 1;
coada.push(make_pair(x,y));
while(!coada.empty())
{
i = coada.front().first;
j = coada.front().second;
coada.pop();
for(int directie = 0; directie < 8; directie++)
{
ii = i + di[directie];
jj = j + dj[directie];
if(OK(ii,jj) && l[ii][jj] == 0 )
{
l[ii][jj] = l[i][j] + 1;
coada.push(make_pair(ii,jj));
}
}
}
}
int main()
{
int i, j, x, y, solutie = 9999;
Read();
Lee(rx,ry,r);
Lee(jx,jy,ju);
for(i=1; i<=n; i++)
for(j=1; j<=m; j++)
if(r[i][j] == ju[i][j] && r[i][j] != 0 )
if(r[i][j] < solutie)
{
solutie = r[i][j];
x = i;
y = j;
}
fout << r[x][y] << " " << x << " " << y << "\n";
fout.close();
return 0;
}