#include <iostream>
#include <fstream>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
struct solutie
{
int timp,x,y;
}sol[10000];
bool mycomp (solutie a , solutie b)
{
if( a.timp != b.timp)
return a.timp < b.timp;
else
return a.y > b.y;
}
struct om
{
int x,y;
};
queue <om> Q1,Q2;
int dl[]={-1,-1,0,1,1,1,0,-1},dc[]={0,1,1,1,0,-1,-1,-1};
int a[105][105],n,u,m,b[105][105];
bool viz[105][105];
bool ok(int x , int y)
{
return ( ( x >= 1 ) && ( x <= n ) && ( y >= 1 ) && ( y <= m ) && a[x][y] != -1 );
}
void BFS(queue <om> Q, int a[105][105])
{
memset(viz,0,sizeof(viz));
while(!Q.empty())
{
om x;
x=Q.front();
Q.pop();
for(int k=0;k<8;k++)
{
om y;
y.x=x.x+dl[k];
y.y=x.y+dc[k];
if( ok( y.x , y.y ) && !viz[y.x][y.y] )
{
viz[y.x][y.y]=1;
if( a[y.x][y.y] != -2 )
{
if( a[ x.x ][ x.y ]+1 < a[ y.x ][ y.y ] )
{
a[ y.x ][ y.y ] = a[ x.x ][ x.y ] + 1;
Q.push(y);
}
}
else
{
a[ y.x ][ y.y ] = a[ x.x ][ x.y ] + 1;
Q.push(y);
}
}
}
}
}
int main()
{
ifstream in("rj.in");
ofstream out("rj.out");
int i,j;
char c;
in>>n>>m;
char s[105];
for(i=1;i<=n;i++)
{
in.get();
in.get(s+1,105);
for(j=1;j<=m;j++)
{
c=s[j];
if(c=='R')
{
a[i][j]=0;
om x;
x.x=i;
x.y=j;
Q1.push(x);
b[i][j]=-1;
}
else
if(c=='J')
{
b[i][j]=0;
om x;
x.x=i;
x.y=j;
Q2.push(x);
a[i][j]=-1;
}
else
if(c=='X')
a[i][j]=-1,b[i][j]=-1;
else
a[i][j]=-2,b[i][j]=-2;
}
}
for(i=0;i<=n+1;i++)
a[i][0]=-1,a[i][n+1]=-1;
for(i=0;i<=m+1;i++)
a[0][i]=-1,a[m+1][i]=-1;
for(i=0;i<=n+1;i++)
b[i][0]=-1,b[i][n+1]=-1;
for(i=0;i<=m+1;i++)
b[0][i]=-1,b[m+1][i]=-1;
BFS(Q1,a);
BFS(Q2,b);
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
if( a[i][j] == b[i][j] && a[i][j] != -1 && a[i][j] != -2 )
{
u++;
sol[u].timp=a[i][j]+1;
sol[u].x=i;
sol[u].y=j;
}
sort(sol+1,sol+u+1,mycomp);
out<<sol[1].timp<<" "<<sol[1].x<<" "<<sol[1].y;
return 0;
}