#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define max 110
#define max2 60010
#define maxlen 8
int l;
char init[max][max];
int romeo[max][max],julieta[max][max];
int sx[max2],sy[max2];
int gps1[maxlen]= {0,1,1,1,0,-1,-1,-1};
int gps2[maxlen]= {-1,-1,0,1,1,1,0,-1};
void BF(int x,int y,int romeo[][max],int n,int m)
{
int i,j,cx,cy;
for (i=1; i<=n; i++)
for (j=0; j<m; j++)
if (init[i][j]=='X')
romeo[i][j]=-1;
else romeo[i][j]=max2;
l=1;
sx[l]=x;
sy[l]=y;
romeo[x][y]=1;
for (i=1; i<=l; i++)
for (j=0; j<maxlen; j++)
{
cx=sx[i]+gps1[j];
cy=sy[i]+gps2[j];
if ((cx > 0) && (cx <= n) && (cy >= 0) && (cy <= m) && (romeo[sx[i]][sy[i]] + 1 < romeo[cx][cy]))
{
l++;
sx[l] = cx;
sy[l] = cy;
romeo[cx][cy] = romeo[sx[i]][sy[i]]+1;
}
}
}
int main()
{
freopen("rj.in", "r", stdin);
freopen("rj.out", "w", stdout);
int n, m, pozx=0, pozy=0;
scanf("%d %d ", &n, &m);
int i, j;
for (i = 1; i <= n; i++)
fgets(init[i], max, stdin);
for (i = 1; i <= n; i++)
for (j = 0; j < m; j++)
if (init[i][j]=='R')
BF(i,j,romeo,n,m);
for (i = 1; i <= n; i++)
for (j=0; j<m; j++)
if (init[i][j]=='J')
BF(i,j,julieta,n,m);
romeo[pozx][pozy]=max2;
for (i = 1; i <= n; i++)
for (j = 0; j < m; j++)
if ((romeo[i][j] != -1) && (romeo[i][j] == julieta[i][j]) && (romeo[i][j] < romeo[pozx][pozy]))
{
pozx = i;
pozy = j;
}
printf("%d %d %d\n", romeo[pozx][pozy], pozx, pozy + 1);
return 0;
}