{"trustable":false,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cscript type\u003d\u0027text/x-mathjax-config\u0027\u003eMathJax.Hub.Config({tex2jax: { inlineMath: [[\u0027$\u0027,\u0027$\u0027]] } }); \u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027 src\u003d\u0027https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\u0027\u003e\u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027\u003esetTimeout(function(){MathJax.Hub.Queue([\u0027Typeset\u0027, MathJax.Hub, \u0027left_view\u0027]);}, 2000);\u003c/script\u003e\n\u003cdiv class\u003d\"panel_content\"\u003e\n本尼有一块宽敞的农田可以灌溉。农田是一个长方形,被分成许多小正方形。水管放置在这些方格中。不同的方形有不同类型的管子。管道有11种类型,从A到K标记,如图1所示。\n \u003cbr\u003e\n \u003cbr\u003e\n \u003ccenter\u003e\n \u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/5ccee528d98fbd47847e51eb3c952d09?v\u003d1629598517\"\u003e\n \u003c/center\u003e\n \u003cbr\u003e\n \u003ccenter\u003e\n Figure 1\n \u003c/center\u003e\n \u003cbr\u003e\n \u003cbr\u003e本尼有一张他农场的地图,上面有一系列标记,表示整个农场的水管分布。例如,如果他有一张地图\n \u003cbr\u003e\n \u003cbr\u003eADC\n \u003cbr\u003eFJK\n \u003cbr\u003eIHE\n \u003cbr\u003e\n \u003cbr\u003e然后水管分布如下\n \u003cbr\u003e\n \u003cbr\u003e\n \u003ccenter\u003e\n \u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/873260580c7a7a940f4ea25346ecdcb3?v\u003d1629598517\"\u003e\n \u003c/center\u003e\n \u003cbr\u003e\n \u003ccenter\u003e\n Figure 2\n \u003c/center\u003e\n \u003cbr\u003e\n \u003cbr\u003e在一些方块的中心发现了几个泉水,所以水可以沿着管道从一个方块流到另一个方块。如果水流过一个方格,这个方格内的整个农田都被灌溉了,秋天就会有丰收。\n\n现在 Benny 想知道至少应该找到多少泉水来灌溉整个农田。你能帮他吗?\n\n注意:在上面的示例中,至少需要 3 个井泉,如图 2 中的红点所示。\n \u003cbr\u003e\n\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"有几个测试用例!在每个测试用例中,第一行包含 2 个整数 M 和 N,然后是 M 行。在每一行中,有 N 个字符,范围为“A”到“K”,表示相应方块上的水管类型。负数 M 或 N 表示输入结束,否则您可以假设 1 \u003c\u003d M, N \u003c\u003d 50。"}},{"title":"Output","value":{"format":"HTML","content":"对于每个测试用例,在一行中输出所需的最少数量的泉眼。 "}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre\u003e2 2\nDK\nHF\n\n3 3\nADC\nFJK\nIHE\n\n-1 -1\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre\u003e2\n3\u003c/pre\u003e"}}]}