h,w=gets.split.map(&:to_i);s=readlines;h.times{|y|w.times{|x|loop{y=(y+1)%h;x=(x+1)%w;c=s[y][x];if"."!=c;if"R"==c;puts"loop";else;p y>0?y:h,x>0?x:w;end;exit;end}if"R"==s[y][x]}}