p=input;h,w=map(int,p().split());s="";q=2e6 for i in range(h): t=p();s+=t if'R'in t:y=t.index('R');x=i while q*(s[x*w+y]!='#'):x=(x+1)%h;y=(y+1)%w;q-=1 print(q and f"{x or h} {y or w}"or"loop")