#include <fstream>
#include <queue>
#include <cstring>
//#include <iostream>
#include <algorithm>
#include <string>
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define pb push_back
#define mp make_pair
#define ALL(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define clr(A,x) memset(A, x, sizeof(A))
#define cpy(A,B) memcpy(A, B, sizeof(B))
#define g(s) getline(fin, s) ///mod
#define FASTIO ios_base::sync_with_stdio(0)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int MAX=100005;
const ull MOD=100003;
const int NR_CIFRE=100005;
/*template <typename T>
string to_string(const T& n){
ostringstream os;
os << n;
return os.str();
}
*/
ifstream fin("rj.in");
ofstream fout("rj.out");
int n, m;
int mat1[101][101];
int rx, ry, jx, jy;
int matcpy[101][101];
void citire();
void lee(int startx, int starty, int mat[][101]);
struct coord
{
int x, y;
};
queue<coord> coada;
int dx[]={0, 0, -1, 1, 1, 1, -1, -1};
int dy[]={1, -1, 0, 0, 1, -1, 1, -1};
int main()
{
citire();
int sol=10000000, solx, soly;
lee(rx, ry, mat1);
lee(jx, jy, matcpy);
for1(i,n)
for1(j, n)
{
if(mat1[i][j]==matcpy[i][j] && mat1[i][j]!=-1 && mat1[i][j]!=0)
{
if(sol>mat1[i][j])
{
sol=mat1[i][j];
solx=i; soly=j;
}
}
}
fout<<sol<<' '<<solx<<' '<<soly;
return 0;
}
void citire()
{
fin>>n>>m;
string s;
g(s); ///mod
for1(i, n)
{
g(s);
for0(j, m)
{
char x=s[j];
//cin>>x;
if(x=='R')
{
mat1[i][j+1]=1;
rx=i;
ry=j+1;
}
else if(x=='J')
{
mat1[i][j+1]=1;
jx=i;
jy=j+1;
}
else if(x=='X')
mat1[i][j+1]=-1;
}
}
cpy(matcpy, mat1);
mat1[jx][jy]=0;
matcpy[rx][ry]=0;
}
void lee(int startx, int starty, int mat[][101])
{
coord p;
p.x=startx;
p.y=starty;
coada.push(p);
while(!coada.empty())
{
p=coada.front();
coada.pop();
for0(k, 8)
{
coord pnou;
pnou.x=p.x+dx[k];
pnou.y=p.y+dy[k];
if(pnou.x<=n && pnou.x>=1 &&
pnou.y<=m && pnou.y>=1 &&
mat[pnou.x][pnou.y]==0)
{
coada.push(pnou);
mat[pnou.x][pnou.y]=mat[p.x][p.y]+1;
}
}
}
// while(!coada.empty())
// coada.pop();
//int ret=mat[finalx][finaly];
// cpy(mat, matcpy);
// return ret==0?102010:ret;
}