using System; using System.Collections.Generic; using System.Linq; class Program { static string ReadLine() { return Console.ReadLine(); } static int ReadInt() { return int.Parse(ReadLine()); } static int[] ReadInts() { return ReadLine().Split().Select(int.Parse).ToArray(); } static string[] ReadStrings() { return ReadLine().Split(); } static void Test() { // m^n が 65535 を超える for (int i = 2; ; i++) { // i 種類の文字を使って p 文字の文字列を作る int p = 1; while (Math.Pow(i, p+1) <= 63353) { p++; } if (i <= p) { Console.WriteLine("{0}^{1} = {2}", i, p, Math.Pow(i, p)); } if (p == 1) break; } } static int RunLength(int[] xs) { int len = 0; int x = xs[0]; int n = 1; for (int i = 1; i < xs.Length; i++) { if (x == xs[i]) { n++; } else { len += 1 + n.ToString().Length; n = 1; } } len += 1 + n.ToString().Length; return len; } static int Calc_1(int p, int[] xs, int m) { if (p == xs.Length) { if (xs.Length > RunLength(xs)) return 1; return 0; } int ret = 0; for (int i = 0; i < m; i++) { xs[p] = i; ret += Calc_1(p+1, xs, m); } return ret; } static int Calc(int m, int n) { var xs = new int[n]; return Calc_1(0, xs, m); } static void Main() { // Test(); var mn = ReadLine().Split(new[] { ',' }).Select(int.Parse).ToArray(); int m = mn[0], n = mn[1]; int ans = Calc(m, n); Console.WriteLine(ans); } } /* Input Output 2,5 10 3,10 2505 4,7 616 2,16 19898 8,5 232 */