{"raw_statement":[{"iden":"problem statement","content":"We have a grid with $H$ horizontal rows and $W$ vertical columns. $(i, j)$ denotes the square at the $i$\\-th row from the top and $j$\\-th column from the left.  \n$(i,j)$ has a character $G_{i,j}$ written on it. $G_{i,j}$ is `U`, `D`, `L`, or `R`.\nYou are initially at $(1,1)$. You repeat the following operation until you cannot make a move.\n\n> Let $(i,j)$ be the square you are currently at.  \n> If $G_{i,j}$ is `U` and $i \\neq 1$, move to $(i-1,j)$.  \n> If $G_{i,j}$ is `D` and $i \\neq H$, move to $(i+1,j)$.  \n> If $G_{i,j}$ is `L` and $j \\neq 1$, move to $(i,j-1)$.  \n> If $G_{i,j}$ is `R` and $j \\neq W$, move to $(i,j+1)$.  \n> Otherwise, you cannot make a move.\n\nPrint the square you end up at when you cannot make a move.  \nIf you indefinitely repeat moving, print `-1` instead."},{"iden":"constraints","content":"*   $1 \\leq H, W \\leq 500$\n*   $G_{i,j}$ is `U`, `D`, `L`, or `R`.\n*   $H$ and $W$ are integers."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$H$ $W$\n$G_{1,1}G_{1,2}\\dots G_{1,W}$\n$G_{2,1}G_{2,2}\\dots G_{2,W}$\n$\\vdots$\n$G_{H,1}G_{H,2}\\dots G_{H,W}$"},{"iden":"sample input 1","content":"2 3\nRDU\nLRU"},{"iden":"sample output 1","content":"1 3\n\nYou will move as $(1, 1) \\to (1, 2) \\to (2, 2) \\to (2, 3) \\to (1, 3)$, ending up here, so the answer is $(1, 3)$."},{"iden":"sample input 2","content":"2 3\nRRD\nULL"},{"iden":"sample output 2","content":"\\-1\n\nYou will indefinitely repeat moving as $(1, 1) \\to (1, 2) \\to (1, 3) \\to (2, 3) \\to (2, 2) \\to (2, 1) \\to (1, 1) \\to (1, 2) \\to \\dots$, so `-1` should be printed in this case."},{"iden":"sample input 3","content":"9 44\nRRDDDDRRRDDDRRRRRRDDDRDDDDRDDRDDDDDDRRDRRRRR\nRRRDLRDRDLLLLRDRRLLLDDRDLLLRDDDLLLDRRLLLLLDD\nDRDLRLDRDLRDRLDRLRDDLDDLRDRLDRLDDRLRRLRRRDRR\nDDLRRDLDDLDDRLDDLDRDDRDDDDRLRRLRDDRRRLDRDRDD\nRDLRRDLRDLLLLRRDLRDRRDRRRDLRDDLLLLDDDLLLLRDR\nRDLLLLLRDLRDRLDDLDDRDRRDRLDRRRLDDDLDDDRDDLDR\nRDLRRDLDDLRDRLRDLDDDLDDRLDRDRDLDRDLDDLRRDLRR\nRDLDRRLDRLLLLDRDRLLLRDDLLLLLRDRLLLRRRRLLLDDR\nRRRRDRDDRRRDDRDDDRRRDRDRDRDRRRRRRDDDRDDDDRRR"},{"iden":"sample output 3","content":"9 5"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}