{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n section pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"Problem statement","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\r\n\u003cp\u003eWe have an \u003cvar\u003e\\(H \\times W\\)\u003c/var\u003e grid whose squares are painted black or white. The square at the \u003cvar\u003e\\(i\\)\u003c/var\u003e-th row from the top and the \u003cvar\u003e\\(j\\)\u003c/var\u003e-th column from the left is denoted as \u003cvar\u003e\\((i, j)\\)\u003c/var\u003e.\u003cbr\u003e\r\nSnuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square \u003cvar\u003e\\((1, 1)\\)\u003c/var\u003e. The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square \u003cvar\u003e\\((H, W)\\)\u003c/var\u003e passing only white squares.\u003cbr\u003e\r\nBefore Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square \u003cvar\u003e\\((1, 1)\\)\u003c/var\u003e and \u003cvar\u003e\\((H, W)\\)\u003c/var\u003e. Also, changes of color must all be carried out before the beginning of the game.\u003cbr\u003e\r\nWhen the game is completed, Snuke\u0027s score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print \u003cvar\u003e\\(-1\\)\u003c/var\u003e if the game cannot be completed, that is, Kenus can never reach square \u003cvar\u003e\\((H, W)\\)\u003c/var\u003e regardless of how Snuke changes the color of the squares. \u003c/p\u003e\r\n\u003cp\u003eThe color of the squares are given to you as characters \u003cvar\u003e\\(s_{i, j}\\)\u003c/var\u003e. If square \u003cvar\u003e\\((i, j)\\)\u003c/var\u003e is initially painted by white, \u003cvar\u003e\\(s_{i, j}\\)\u003c/var\u003e is \u003ccode\u003e.\u003c/code\u003e; if square \u003cvar\u003e\\((i, j)\\)\u003c/var\u003e is initially painted by black, \u003cvar\u003e\\(s_{i, j}\\)\u003c/var\u003e is \u003ccode\u003e#\u003c/code\u003e.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Constraints","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\r\n\u003cul\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(H\\)\u003c/var\u003e is an integer between \u003cvar\u003e\\(2\\)\u003c/var\u003e and \u003cvar\u003e\\(50\\)\u003c/var\u003e (inclusive).\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(W\\)\u003c/var\u003e is an integer between \u003cvar\u003e\\(2\\)\u003c/var\u003e and \u003cvar\u003e\\(50\\)\u003c/var\u003e (inclusive).\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(s_{i, j}\\)\u003c/var\u003e is \u003ccode\u003e.\u003c/code\u003e or \u003ccode\u003e#\u003c/code\u003e \u003cvar\u003e\\((1 \\leq i \\leq H, 1 \\leq j \\leq W)\\)\u003c/var\u003e.\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(s_{1, 1}\\)\u003c/var\u003e and \u003cvar\u003e\\(s_{H, W}\\)\u003c/var\u003e are \u003ccode\u003e.\u003c/code\u003e.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Input","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\r\n\u003cp\u003eInput is given from Standard Input in the following format:\u003c/p\u003e\r\n\u003cpre\u003e\u003cvar\u003e\\(H\\)\u003c/var\u003e \u003cvar\u003e\\(W\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W}\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W}\\)\u003c/var\u003e\r\n \u003cvar\u003e\\(:\\)\u003c/var\u003e \u003cvar\u003e\\(:\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}\\)\u003c/var\u003e\r\n\u003c/pre\u003e\r\n\r\n\u003c/section\u003e\r\n"}},{"title":"Output","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\r\n\u003cp\u003ePrint the maximum possible score that Snuke can achieve, or print \u003cvar\u003e\\(-1\\)\u003c/var\u003e if the game cannot be completed.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 1","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3 3\r\n..#\r\n#..\r\n...\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003cp\u003eThe score \u003cvar\u003e\\(2\\)\u003c/var\u003e can be achieved by changing the color of squares as follows:\u003c/p\u003e\r\n\u003cp\u003e\u003cimg alt\u003d\"Explanation of Sample 1\" src\u003d\"CDN_BASE_URL/b02edc6d04286d1c86a47b2f4c7282fa?v\u003d1715209202\"\u003e\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 2","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e10 37\r\n.....................................\r\n...#...####...####..###...###...###..\r\n..#.#..#...#.##....#...#.#...#.#...#.\r\n..#.#..#...#.#.....#...#.#...#.#...#.\r\n.#...#.#..##.#.....#...#.#.###.#.###.\r\n.#####.####..#.....#...#..##....##...\r\n.#...#.#...#.#.....#...#.#...#.#...#.\r\n.#...#.#...#.##....#...#.#...#.#...#.\r\n.#...#.####...####..###...###...###..\r\n.....................................\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e209\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\u003c/section\u003e\r\n"}}]}