#include <iostream>
#include <fstream>
using namespace std;
ifstream f("RJ.in");
ofstream g("RJ.out");
int n,m,a[100][100],b[100][100];
void citire()
{
int i,j;
char x;
f>>n>>m;
for(i=1;i<=n;i++)
{
f>>noskipws>>x;
for(j=1;j<=m;j++)
{
f>>noskipws>>x;
if(x==' ')a[i][j]=0;
if(x=='X')a[i][j]=-1;
if(x=='R')a[i][j]=1;
if(x=='J')a[i][j]=1;
}
}
}
void bordare()
{
int i;
for(i=0;i<=n+1;i++)
{
a[0][i]=-1;
a[n+1][i]=-1;
a[i][0]=-1;
a[i][n+1]=-1;
}
}
void umplere(int k, int i, int j, int x[100][100])
{
if(x[i][j]!=-1)
{
if(x[i][j]==0)
{
x[i][j]=k;
umplere(k+1,i+1,j-1,x);
umplere(k+1,i+1,j,x);
umplere(k+1,i+1,j+1,x);
umplere(k+1,i,j-1,x);
umplere(k+1,i,j+1,x);
umplere(k+1,i-1,j-1,x);
umplere(k+1,i-1,j,x);
umplere(k+1,i-1,j+1,x);
}
else
{
if(k<x[i][j])
{x[i][j]=k;
umplere(k+1,i+1,j-1,x);
umplere(k+1,i+1,j,x);
umplere(k+1,i+1,j+1,x);
umplere(k+1,i,j-1,x);
umplere(k+1,i,j+1,x);
umplere(k+1,i-1,j-1,x);
umplere(k+1,i-1,j,x);
umplere(k+1,i-1,j+1,x);
}
}
}
}
int main()
{
int i,j,x,y,q,w;
citire();
bordare();
for(i=0;i<=n+1;i++)
for(j=0;j<=m+1;j++)
b[i][j]=a[i][j];
x=0;y=0;
for(i=1;i<=n&&x==0;i++)
for(j=1;j<=n;j++)
{
if(a[i][j]==1)
{
x=i;
y=j;
}
}
umplere(2,x-1,y,a);
umplere(2,x-1,y+1,a);
umplere(2,x-1,y-1,a);
umplere(2,x,y+1,a);
umplere(2,x,y-1,a);
umplere(2,x+1,y-1,a);
umplere(2,x+1,y,a);
umplere(2,x+1,y+1,a);
q=0;w=0;
for(i=n;i>=1&&q==0;i--)
for(j=m;j>=1;j--)
{
if(b[i][j]==1)
{
q=i;
w=j;
}
}
umplere(2,q-1,w+1,b);
umplere(2,q-1,w-1,b);
umplere(2,q-1,w,b);
umplere(2,q,w+1,b);
umplere(2,q,w-1,b);
umplere(2,q+1,w-1,b);
umplere(2,q+1,w,b);
umplere(2,q+1,w+1,b);
int mr=999999,mi=0,mj=0;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{
if(a[i][j]==b[i][j]&&a[i][j]>1)
{
if(a[i][j]<mr)
{
mr=a[i][j];
mi=i;
mj=j;
}
}
}
g<<mr<<" "<<mi<<" "<<mj;
return 0;
}