{"problem":{"name":"Belt Conveyor","description":{"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.   $(i,j)$ has a character $G_{i,j}$ writ","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc265_c"},"statements":[{"statement_type":"Markdown","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.\n\n## Constraints\n\n*   $1 \\leq H, W \\leq 500$\n*   $G_{i,j}$ is `U`, `D`, `L`, or `R`.\n*   $H$ and $W$ are integers.\n\n## Input\n\nInput 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}$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc265_c","tags":[],"sample_group":[["2 3\nRDU\nLRU","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)$."],["2 3\nRRD\nULL","\\-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."],["9 44\nRRDDDDRRRDDDRRRRRRDDDRDDDDRDDRDDDDDDRRDRRRRR\nRRRDLRDRDLLLLRDRRLLLDDRDLLLRDDDLLLDRRLLLLLDD\nDRDLRLDRDLRDRLDRLRDDLDDLRDRLDRLDDRLRRLRRRDRR\nDDLRRDLDDLDDRLDDLDRDDRDDDDRLRRLRDDRRRLDRDRDD\nRDLRRDLRDLLLLRRDLRDRRDRRRDLRDDLLLLDDDLLLLRDR\nRDLLLLLRDLRDRLDDLDDRDRRDRLDRRRLDDDLDDDRDDLDR\nRDLRRDLDDLRDRLRDLDDDLDDRLDRDRDLDRDLDDLRRDLRR\nRDLDRRLDRLLLLDRDRLLLRDDLLLLLRDRLLLRRRRLLLDDR\nRRRRDRDDRRRDDRDDDRRRDRDRDRDRRRRRRDDDRDDDDRRR","9 5"]],"created_at":"2026-03-03 11:01:14"}}