{"problem":{"name":"Fences","description":{"content":"There are some goats on a grid with $H$ rows and $W$ columns. Alice wants to put some fences at some cells where goats do not exist so that no goat can get outside the grid. Goats can move in the four","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"kupc2016_e"},"statements":[{"statement_type":"Markdown","content":"There are some goats on a grid with $H$ rows and $W$ columns. Alice wants to put some fences at some cells where goats do not exist so that no goat can get outside the grid. Goats can move in the four directions, that is, up, down, right and left. Goats can not move onto the cells where fences are placed. If a goat exists at one of the outermost cells in the grid, it can move outside. Goats do not move until all fences are placed. Find the minimum number of fences to be placed.\n\n## Constraints\n\n*   $1 \\leq H \\leq 100$\n*   $1 \\leq W \\leq 100$\n*   There is at least one goat on the given grid.\n\n## Input\n\nThe input is given from the Standart Input in the following format:\n\n$H$ $W$\n$S_1$\n:\n$S_H$\n\nThe $j$\\-th $(1 \\leq j \\leq W)$ character in $S_i$ $(1 \\leq i \\leq H)$ represents whether a goat exists at the cell located at row $i$ and column $j$. Character `.` represents there is no goat, and `X` represents there is one goat at the cell.\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"kupc2016_e","tags":[],"sample_group":[["4 5\n.....\n.....\n..X..\n.....","4\n\nThe optimum answer is to put fences at the cells located at row $3$ and column $2$, row $2$ and column $3$, row $3$ and column $4$, and row $4$ and column $3$."],["2 2\n..\n.X","\\-1\n\nIn this case, there is no way to keep the goats inside the grid."],["6 6\n......\n......\n..X...\n.X..X.\n..X...\n......","10"]],"created_at":"2026-03-03 11:01:14"}}