{"trustable":true,"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":"\u003cdiv class\u003d\"panel_content\"\u003eBenny has a spacious farm land to irrigate. The farm land is a rectangle, and is divided into a lot of samll squares. Water pipes are placed in these squares. Different square has a different type of pipe. There are 11 types of pipes, which is marked from A to K, as Figure 1 shows.\u003cbr\u003e\u003cbr\u003e\u003ccenter\u003e\u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/5ccee528d98fbd47847e51eb3c952d09?v\u003d1715514873\"\u003e\u003c/center\u003e\u003cbr\u003e\u003ccenter\u003eFigure 1\u003c/center\u003e\u003cbr\u003e\u003cbr\u003eBenny has a map of his farm, which is an array of marks denoting the distribution of water pipes over the whole farm. For example, if he has a map \u003cbr\u003e\u003cbr\u003eADC\u003cbr\u003eFJK\u003cbr\u003eIHE\u003cbr\u003e\u003cbr\u003ethen the water pipes are distributed like \u003cbr\u003e\u003cbr\u003e\u003ccenter\u003e\u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/873260580c7a7a940f4ea25346ecdcb3?v\u003d1715514873\"\u003e\u003c/center\u003e\u003cbr\u003e\u003ccenter\u003eFigure 2\u003c/center\u003e\u003cbr\u003e\u003cbr\u003eSeveral wellsprings are found in the center of some squares, so water can flow along the pipes from one square to another. If water flow crosses one square, the whole farm land in this square is irrigated and will have a good harvest in autumn. \u003cbr\u003e\u003cbr\u003eNow Benny wants to know at least how many wellsprings should be found to have the whole farm land irrigated. Can you help him? \u003cbr\u003e\u003cbr\u003eNote: In the above example, at least 3 wellsprings are needed, as those red points in Figure 2 show.\u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"There are several test cases! In each test case, the first line contains 2 integers M and N, then M lines follow. In each of these lines, there are N characters, in the range of \u0027A\u0027 to \u0027K\u0027, denoting the type of water pipe over the corresponding square. A negative M or N denotes the end of input, else you can assume 1 \u0026lt;\u003d M, N \u0026lt;\u003d 50.\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each test case, output in one line the least number of wellsprings needed.\u003cbr\u003e"}},{"title":"Sample","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\u003e2 2\r\nDK\r\nHF\r\n\r\n3 3\r\nADC\r\nFJK\r\nIHE\r\n\r\n-1 -1\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\r\n3\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}