You are given a string $s$ of length $n$, which consists only of the first $k$ letters of the Latin alphabet. All letters in string $s$ are uppercase.

A subsequence of string $s$ is a string that can be derived from $s$ by deleting some of its symbols without changing the order of the remaining symbols. For example, "ADE" and "BD" are subsequences of "ABCDE", but "DEA" is not.

A subsequence of $s$ called good if the number of occurences of each of the first $k$ letters of the alphabet is the same.

Find the length of the longest good subsequence of $s$. 


-----Input-----

The first line of the input contains integers $n$ ($1\le n \le 10^5$) and $k$ ($1 \le k \le 26$).

The second line of the input contains the string $s$ of length $n$. String $s$ only contains uppercase letters from 'A' to the $k$-th letter of Latin alphabet.


-----Output-----

Print the only integer — the length of the longest good subsequence of string $s$.


-----Examples-----
Input
9 3
ACAABCCAB

Output
6
Input
9 4
ABCABCABC

Output
0


-----Note-----

In the first example, "ACBCAB" ("ACAABCCAB") is one of the subsequences that has the same frequency of 'A', 'B' and 'C'. Subsequence "CAB" also has the same frequency of these letters, but doesn't have the maximum possible length.

In the second example, none of the subsequences can have 'D', hence the answer is $0$.

Difficulty: EASY

Solutions:
def main_function():
	(n, m) = [int(i) for i in input().split(' ')]
	s = list(input())
	d = {}
	for i in s:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	if len(d) < m:
		return 0
	f = min(d, key=lambda i: d[i])
	return d[f] * m
print(main_function())


def main():
	(n, k) = map(int, input().split())
	string = input()
	occ = [0] * 26
	for c in string:
		occ[ord(c) - ord('A')] += 1
	res = occ[0]
	for i in range(k):
		res = min(occ[i], res)
	print(res * k)
main()


(n, k) = map(int, input().split())
aa = input()
a = []
for i in aa:
	a.append(i)
m = 0
l = []
i = 65
while i < 65 + k:
	c = a.count(chr(i))
	l.append(c)
	i = i + 1
b = min(l)
print(b * k)


k = int(input().split()[1])
s = input()
print(k * min((s.count(chr(65 + i)) for i in range(k))))


import math
import sys
import re
(n, k) = map(int, input().rstrip().split())
s = input()
s1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
s2 = s1[:k]
l1 = []
for x in s2:
	l1.append(s.count(x))
print(min(l1) * k)


import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)

def getIntList():
	return list(map(int, input().split()))
try:
	import numpy

	def dprint(*args, **kwargs):
		print(*args, **kwargs, file=sys.stderr)
	dprint('debug mode')
except ModuleNotFoundError:

	def dprint(*args, **kwargs):
		pass
inId = 0
outId = 0
if inId > 0:
	dprint('use input', inId)
	sys.stdin = open('input' + str(inId) + '.txt', 'r')
if outId > 0:
	dprint('use output', outId)
	sys.stdout = open('stdout' + str(outId) + '.txt', 'w')
	atexit.register(lambda : sys.stdout.close())
(N, K) = getIntList()
zs = input()
t = {}
for x in zs:
	if x not in t:
		t[x] = 1
	else:
		t[x] += 1
ff = 100000
for y in t:
	ff = min(ff, t[y])
if len(t) < K:
	ff = 0
print(ff * K)


(n, k) = map(int, input().split())
s = input()
t = [0] * 26
for (i, v) in enumerate(s):
	t[ord(v) - ord('A')] += 1
print(min(t[:k]) * k)


(n, k) = map(int, input().split())
l = list(input())
y = list(set(l))
ans = []
if len(y) < k:
	print(0)
	exit()
for i in range(len(y)):
	ans.append(l.count(y[i]))
print(min(ans) * k)


def inv(x):
	return chr(x + 96).upper()
number = []
(n, k) = map(int, input().split())
string = input()
for i in range(1, k + 1):
	alpha = inv(i)
	number.append(string.count(alpha))
if 0 in number:
	print(0)
else:
	m = min(number)
	print(m * k)


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
s = list(input())
l = set(s[:n])
if len(l) < k:
	print(0)
else:
	g = []
	for i in l:
		g.append(s.count(i))
	g.sort()
	print(k * g[-k])


def main():
	(n, k) = [int(v) for v in input().split()]
	d = input()
	freq = {}
	for c in d:
		if c not in freq:
			freq[c] = 0
		freq[c] += 1
	data = min([freq[chr(ord('A') + c)] if chr(ord('A') + c) in freq else 0 for c in range(0, k)])
	print(data * k)
main()


(a, b) = map(int, input().split())
x = list(input())
z = set(x)
v = []
if len(z) == b:
	for i in z:
		v.append(x.count(i))
	print(min(v) * b)
else:
	print(0)


import string
from collections import defaultdict

def solve():
	ucase = list(string.ascii_uppercase)
	freq = defaultdict(int)
	(n, k) = map(int, input().split())
	s = input()
	for c in s:
		freq[c] += 1
	min_ = 10 ** 10
	allowed = set()
	for i in range(k):
		allowed.add(ucase[i])
		if freq[ucase[i]] < min_:
			min_ = freq[ucase[i]]
	if min_ == 0:
		print(0)
		return
	length = min_ * k
	print(length)
solve()


(n, k) = map(int, input().split())
s = input()
p = [0] * k
t = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
b = t[:k]
for i in s:
	if i in b:
		p[ord(i) - 65] += 1
print(min(p) * k)


lis = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
(n, k) = map(int, input().split())
test = str(input())
lis1 = lis[:k]
ch = n
for x in lis1:
	y = test.count(x)
	if y < ch:
		ch = y
	else:
		pass
print(k * ch)


(n, k) = map(int, input().split())
s = input()
ct = [0] * k
for i in s:
	ct[ord(i) - ord('A')] += 1
print(min(ct) * k)


(n, k) = map(int, input().split())
s = input()
l = []
for z in range(k):
	l.append(0)
for i in s:
	for j in range(65, 65 + k + 1):
		if ord(i) == j:
			l[j - 65] += 1
print(k * min(l))


(n, k) = list(map(int, input().split(' ')))
s = input()
min = 99999999
for i in range(k):
	val = s.count(chr(65 + i))
	if min > val:
		min = val
print(min * k)


__author__ = 'Dilshod'
(n, k) = map(int, input().split())
count = [1000000000] * (k + 1)
s = input()
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
letters = letters[:k]
for i in s:
	a = letters.find(i)
	if count[a + 1] == 1000000000:
		count[a + 1] = 0
	count[a + 1] += 1
count = count[1:]
if 1000000000 in count:
	print(0)
	exit()
print(min(count) * k)


(a, b) = map(int, input().split())
d = list(input())
(c, m) = ([], [])
for x in range(65, 65 + b):
	c.append(chr(x))
if len(set(d)) == len(c):
	for x in range(b):
		m.append(d.count(c[x]))
	print(min(m) * b)
else:
	print(0)


str_num = input()
list_num = str_num.split()
n = int(list_num[0])
k = int(list_num[1])
str_1 = input()
dict_1 = {}
count = 0
for i in range(n):
	if str_1[i] in dict_1.keys():
		dict_1[str_1[i]] += 1
	else:
		dict_1.update({str_1[i]: 1})
		count += 1
if count < k:
	print(0)
else:
	min_val = dict_1.get(str_1[0])
	for key in dict_1.keys():
		if dict_1.get(key) < min_val:
			min_val = dict_1.get(key)
	print(min_val * k)


(n, k) = map(int, input().split())
s = list(input())
a = [s.count(chr(i + 65)) for i in range(k)]
print(min(a) * k)


(n, k) = map(int, input().split(' '))
s = input()
occurences = k * [0]
for i in range(n):
	occurences[ord(s[i]) - 65] += 1
print(min(occurences) * k)


from collections import Counter

def __starting_point():
	(n, k) = list(map(int, input().split()))
	s = input()
	c = Counter(s)
	min_symbols = min((c[chr(ord('A') + i)] for i in range(k)))
	print(min_symbols * k)
__starting_point()


l = list(map(int, input().split()))
word = str(input())
n = l[0]
k = l[1]
a = '0ABCDEFGHIJKLMNOPQRSTUVWXYZ'
count = [0] * 27
i = 1
j = 0
while i <= k:
	while j < len(word):
		if a[i] == word[j]:
			count[i] += 1
		j += 1
	j = 0
	i += 1
i = 1
less = 10 ** 6
while i <= k:
	if count[i] < less:
		less = count[i]
	i += 1
print(less * k)


(n, k) = map(int, input().split())
a = input()
letters = [0] * k
for el in a:
	letters[ord(el) - ord('A')] += 1
print(min(letters) * k)


k = int(input().split()[1])
s = input()
print(min((s.count(c) for c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[:k])) * k)


(n, k) = map(int, input().split())
s = input()
print(min([s.count(chr(ord('A') + i)) for i in range(k)]) * k)


(n, k) = map(int, input().split())
mas = [0] * k
s = input()
for i in range(n):
	if ord(s[i]) - ord('A') < k:
		mas[ord(s[i]) - ord('A')] += 1
print(min(mas) * k)


[n, k] = [int(x) for x in input().split()]
cnt = [0 for x in range(k)]
S = input()
for ch in S:
	cnt[ord(ch) - ord('A')] += 1
print(min(cnt) * k)


(n, k) = [int(x) for x in input().split(' ')]
s = input()
if len(set(s)) != k:
	print(0)
else:
	tmp = []
	val = 65
	for i in range(val, val + k):
		tmp.append(s.count(chr(i)))
	print(min(tmp) * k)


from collections import defaultdict
(_, k) = [int(num) for num in input().split(' ')]
letters = input()
if len(set(letters)) < k:
	print(0)
else:
	counter = defaultdict(int)
	for letter in letters:
		counter[letter] += 1
	min_ = sorted(counter.items(), key=lambda x: x[1])[0][1]
	print(min_ * k)


(n, k) = map(int, input().split())
s = input()
d = {}
for i in range(65, 65 + k):
	d[chr(i)] = s.count(chr(i))
print(min(d.values()) * k)


(n, k) = list(map(int, input().split()))
s = input()
mapping = 10 ** 10
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for i in range(k):
	if s.count(alphabet[i]) < mapping:
		mapping = s.count(alphabet[i])
print(mapping * k)


(n, k) = map(int, input().split())
a = list(input())
d = {}
for i in a:
	d[i] = d.get(i, 0) + 1
for i in range(ord('A'), ord('A') + 26):
	d[chr(i)] = d.get(chr(i), 0)
m = 1000000000
for i in range(ord('A'), ord('A') + k):
	if m > d[chr(i)]:
		m = d[chr(i)]
print(m * k)


(n, m) = map(int, input().split())
s = input()
z = []
x = 'A'
for i in range(26):
	a = s.count(x)
	z.append(a)
	x = ord(x) + 1
	x = chr(x)
list2 = z[0:m]
list1 = z[m:26]
if 0 in list2:
	print('0')
else:
	h = min(list2) * m
	h = sum(list1) + h
	print(h)


(n, k) = map(int, input().split())
s = input()
a = 'A'
arr = [0 for i in range(k)]
for c in s:
	if ord(c) - ord(a) <= k - 1:
		arr[ord(c) - ord(a)] += 1
print(min(arr) * len(arr))


(n, k) = map(int, input().split())
st = list(input())
lp = []
l = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
for i in range(k):
	lp.append(l[i])
l_count = []
for i in lp:
	l_count.append(st.count(i))
print(min(l_count) * k)


(n, k) = [int(x) for x in input().split()]
l = [0] * k
for i in [ord(x) - 65 for x in input()]:
	l[i] += 1
print(min(l) * k)


k = input().split(' ')[1]
k = int(k)
m = []
s = list(input())
for i in range(k):
	m.append(s.count(chr(65 + i)))
print(min(m) * k)


(n, m) = map(int, input().split())
s = input()
a = []
for i in range(m):
	a.append(chr(65 + i))
c = []
for i in a:
	c.append(s.count(i))
print(min(c) * m)


import string
alpha = list(string.ascii_uppercase)
(m, n) = map(int, input().split())
s = list(input())
x = []
for i in range(n):
	x.append(s.count(alpha[i]))
print(min(x) * n)


(n, k) = map(int, input().split())
s = input()
alpha = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
l = [0] * k
for i in range(k):
	l[i] = s.count(alpha[i])
l.sort()
print(l[0] * k)


a = list(input().split(' '))
(n, k) = (int(a[0]), int(a[1]))
a = input()
alpha = list((0 for _ in range(26)))
for i in range(len(a)):
	alpha[ord(a[i]) - ord('A')] += 1
check = True
for i in range(1, k):
	if alpha[i] == 0:
		check = False
		break
if check:
	res = int(10000000000000.0)
	for i in range(k):
		res = min(res, alpha[i])
	print(res * k)
else:
	print(0)


USE_STDIO = False
if not USE_STDIO:
	try:
		import mypc
	except:
		pass
from collections import Counter

def main():
	(n, k) = list(map(int, input().split(' ')))
	s = input()
	cnts = Counter(s)
	ans = n
	for i in range(k):
		ch = chr(ord('A') + i)
		ans = min(ans, cnts.get(ch, 0))
	print(ans * k)

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
ar = []
a = input()
arr = list(a)
newlist = list(set(arr))
if len(set(arr)) != k:
	print(0)
else:
	for i in newlist:
		t = arr.count(i)
		ar.append(t)
	print(min(ar) * k)


(k, n) = input().split()
s = input()
alph = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
b = list(s)
b = sorted(b)
last_let = b[-1]
last_let = alph.index(last_let)
if int(n) > last_let + 1:
	print(0)
else:
	y = b.count(alph[0])
	for i in range(int(n)):
		u = b.count(alph[i])
		if u < y:
			y = u
	print(y * int(n))


(n, k) = map(int, input().split())
s = input()
m = n + 1
for i in range(k):
	m1 = s.count(chr(i + 65))
	if m1 < m:
		m = m1
print(m * k)


(n, k) = map(int, input().split())
lis = [0] * 26
s = input()
for i in range(n):
	aa = ord(s[i]) - ord('A')
	lis[aa] += 1
ans = k * min(lis[:k])
print(ans)


l = list(map(int, input().split()))
n = l[0]
k = l[1]
s = input()
a = [0] * k
for i in s:
	a[ord(i) - ord('A')] += 1
print(min(a) * k)


(n, k) = map(int, input().split())
s = input()
if len(set(s)) != k:
	print('0')
else:
	m = 9999999999999
	for i in set(s):
		m = min(m, s.count(i))
	print(m * k)


import sys
import math
lines = sys.stdin.read().splitlines()
(n, k) = [int(x) for x in lines[0].split()]
s = lines[1]
counts = [0] * k
for letter in s:
	counts[ord(letter) - ord('A')] += 1
print(min(counts) * k)


x = list(map(int, input().split()))
y = str(input())
k = x[1]
alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
list = [0] * 27
i = 0
c = 0
flag = True
while i < k:
	while c < len(y):
		if y[c] == alpha[i]:
			list[i] = list[i] + 1
		c += 1
	i += 1
	c = 0
i = 0
min = 100000
while i < k:
	if list[i] == 0:
		flag = False
		break
	elif min > list[i] and min != 0:
		min = list[i]
	i += 1
if flag:
	print(min * k)
else:
	print(0)


(n, k) = map(int, input().split())
rec = [0] * k
s = input()
num = 0
for i in range(n):
	rec[ord(s[i]) - ord('A')] += 1
print(min(rec) * k)


from collections import Counter
(n, k) = map(int, input().split())
string = input()
cow = Counter()
for i in range(k):
	c = 65 + i
	cow[chr(c)] = 0
for i in string:
	cow[i] += 1
lis = cow.values()
print(min(lis) * k)


from sys import stdin, stdout, setrecursionlimit
for _ in range(1):
	ok = {}
	(n, k) = map(int, input().split())
	s = input()
	mn = 9999999
	for x in s:
		if x not in ok:
			ok[x] = 1
		else:
			ok[x] += 1
	if len(ok) != k:
		print(0)
		break
	for key in ok:
		mn = min(ok[key], mn)
	print(mn * k)


(n, k) = map(int, input().split())
st = input()
min = 1000000000000000000000000000000000
s = set(st)
if len(s) != k:
	print(0)
else:
	for i in s:
		if st.count(i) < min:
			min = st.count(i)
	print(min * k)


from collections import Counter
(n, k) = map(int, input().split())
s = Counter(input())
print(min((s[c] for c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[:k])) * k)


H = list(map(int, input().split()))
n = H[0]
k = H[1]
A = input()
B = []
t = ord('A')
for i in range(k):
	B.append(chr(ord('A') + i))
C = [0] * k
for i in range(n):
	C[ord(A[i]) - t] += 1
print(min(C) * k)


a = list(map(int, input().split()))
b = input()
l = [0] * a[1]
for i in range(a[0]):
	l[ord(b[i]) - 65] += 1
m = min(l)
print(m * a[1])


from collections import Counter
(n, k) = map(int, input().split())
cnt = Counter(input())
if len(cnt) < k:
	print(0)
else:
	print(min(cnt.values()) * k)


import string
(n, k) = list(map(int, input().split()))
word = input()
abc = list(string.ascii_uppercase)[:k]
m = []
for i in abc:
	m.append(word.count(i))
print(min(m) * k)


(n, k) = map(int, input().split())
s = input()
from collections import defaultdict as dd
d = dd(lambda : 0)
if len(set(s)) != k:
	print(0)
else:
	for i in s:
		d[i] += 1
	a = min(d.values())
	print(a * k)


from collections import Counter
s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
(n, k) = map(int, input().strip().split())
r = input()
d1 = {}
for i in s:
	d1[i] = 0
d = Counter(r)
d1.update(d)
f = 100000000
for i in range(k):
	f = min(f, d1[s[i]])
print(f * k)


(n, k) = map(int, input().split())
s = sorted(input())
(p, c, a) = (s[0], 0, [])
for i in range(len(s)):
	if s[i] == p:
		c += 1
	else:
		a.append(c)
		c = 1
		p = s[i]
a.append(c)
if len(a) < k:
	k = 0
print(min(a) * k)


(n, k) = map(int, input().split())
s = input()
d = {}
for i in s:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
if len(d) != k:
	print(0)
else:
	print(min(d.values()) * k)


(n, k) = map(int, input().split())
s = input()
di = {}
for i in range(k):
	if chr(65 + i) not in di:
		di[chr(65 + i)] = 0
for i in s:
	if i in di:
		di[i] += 1
l = list(di.values())
res = min(l) * k
print(res)


from string import ascii_uppercase
from collections import Counter
letters = ascii_uppercase
(n, k) = map(int, input().split())
s = input()
c = Counter(s)
print(k * min((c[letter] for letter in letters[:k])))


(x, y) = map(int, input().split())
a = list(map(str, input()))
b = list()
j = 1
j = int(j)
for i in range(y - 1):
	b.append(a.count(chr(ord('A') + j)))
	j = j + 1
b.append(a.count('A'))
print(min(b) * y)


D = False

def sol():
	(N, K) = [int(x) for x in input().split(' ')]
	lst = input()
	a_value = ord('A')
	necessary = {}
	for i in range(a_value, a_value + K):
		necessary[chr(i)] = True
	if D:
		print(necessary)
	letters = {}
	for c in lst:
		if not c in letters:
			letters[c] = 0
		letters[c] += 1
	if D:
		print(letters)
	min_value = float('inf')
	for k in necessary:
		if not k in letters:
			return 0
		if letters[k] < min_value:
			min_value = letters[k]
	if D:
		print(min_value)
	best_length = 0
	for i in range(1, min_value + 1):
		current_length = 0
		for k in letters:
			if letters[k] >= i:
				current_length += i
		best_length = max(best_length, current_length)
	if D:
		print('best:', best_length)
	return best_length
ans = sol()
print(ans)


(n, k) = map(int, input().split())
s = input()
a = [0] * k
for i in s:
	a[abs(ord(i) - 65)] += 1
print(min(a) * k)


from collections import Counter
(n, k) = list(map(int, input().split()))
c = Counter(input())
ans = min((c[chr(ord('A') + i)] for i in range(k)))
print(k * ans)


(n, k) = (int(x) for x in input().split())
s = list(input())
al = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
al = al[:k]
c = []
for i in range(k):
	c.append(s.count(al[i]))
print(min(c) * k)


import string
(n, k) = map(int, input().split())
s = input()
aktmin = n
for b in string.ascii_uppercase[:k]:
	aktmin = min(aktmin, s.count(b))
print(k * aktmin)


(n, k) = map(int, input().split())
a = input()
l = 65 + k
c = []
for i in range(65, l):
	c.append(a.count(chr(i)))
q = min(c)
if q != 0:
	print(k * q)
else:
	print(0)


alps = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
(n, k) = map(int, input().split())
s = input()
print(min([s.count(i) for i in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[:k]]) * k)


nk = input().split()
s = input()
n = nk[0]
k = int(nk[1])
dic = {}
for i in s:
	if i in dic:
		dic[i] += 1
	else:
		dic[i] = 1
m = min(dic.values())
if len(dic) == k:
	result = m * k
else:
	result = 0
print(result)


(n, k) = map(int, input().split())
s = input()
a = [0 for i in range(k)]
for i in range(n):
	a[ord(s[i]) - 65] += 1
a.sort()
print(a[0] * k)


from sys import stdin, stdout, setrecursionlimit
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007
s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
(n, k) = iia()
q = is1()
d = Counter(q)
res = float('inf')
for i in range(k):
	res = min(res, d[s[i]])
print(res * k)


from collections import Counter
(n, k) = map(int, input().split())
s = input()
d = Counter(s)
if len(d.keys()) != k:
	print(0)
else:
	print(min(d.values()) * k)


temp = list(map(int, input().rstrip().split(' ')))
n = temp[0]
k = temp[1]
s = input()
s = list(s)
low = n
t = set(s)
t = list(t)
for i in range(len(t)):
	c = s.count(t[i])
	if c < low:
		low = c
f = 0
for i in range(k):
	if s.count(chr(65 + i)) < low:
		f = 1
if f == 1:
	print(0)
else:
	print(k * low)


def solve(s, n):
	ans = float('inf')
	for i in range(n):
		tmp = s.count(chr(65 + i))
		ans = min(tmp, ans)
	return ans * n
(k, n) = list(map(int, input().strip().split()))
s = input()
print(solve(s, n))


from collections import Counter
(n, k) = map(int, input().split())
s = input()
x = Counter(s)
if len(set(s)) != k:
	print(0)
else:
	print(x[min(x, key=x.get)] * k)


(n, k) = map(int, input().split())
a = [0] * 300
s = input()
se = set()
for i in s:
	x = ord(i)
	se.add(x)
	a[x] += 1
mn = ord('A')
z = 10 ** 9
for i in range(mn, mn + k):
	z = min(z, a[i])
print(z * len(se))


(k, a) = (int(input().split()[1]), input())
print(k * min((a.count(chr(x)) for x in range(65, 65 + k))))


(n, k) = input().split()
n = int(n)
k = int(k)
s = input()
import string
a = string.ascii_uppercase
b = []
for i in a:
	b.append(i)
c = []
for j in b[0:k]:
	c.append(s.count(j))
print(min(c) * k)


t = list(map(int, input().split()))
s = input()
r = []
n = t[0]
l = t[1]
for i in range(n):
	r.append(s[i])
alpha = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
max = 9999999
for j in range(l):
	if max > r.count(alpha[j]):
		max = r.count(alpha[j])
print(max * l)


import string
st = string.ascii_uppercase
s = input()
l = s.split()
n = int(l[0])
k = int(l[1])
l = []
s = input()
l2 = []
for i in range(len(s)):
	l.append(s[i])
for i in range(k):
	l2.append(s.count(st[i]))
l2.sort()
print(l2[0] * k)


(n, k) = input().strip().split()
(n, k) = (int(n), int(k))
string = input().strip()
di = {}
for s in string:
	if s in di.keys():
		di[s] += 1
	else:
		di[s] = 1
values = di.values()
if len(di) < k:
	print(0)
else:
	print(k * min(values))


(n, k) = map(int, input().split())
s = input()
c = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0, 'F': 0, 'G': 0, 'H': 0, 'I': 0, 'J': 0, 'K': 0, 'L': 0, 'M': 0, 'N': 0, 'O': 0, 'P': 0, 'Q': 0, 'R': 0, 'S': 0, 'T': 0, 'U': 0, 'V': 0, 'W': 0, 'X': 0, 'Y': 0, 'Z': 0}
for i in range(n):
	c[s[i]] += 1
d = sorted(c.items(), key=lambda x: x[1], reverse=True)
print(d[k - 1][1] * k)


(n, k) = map(int, input().split())
s = input()
score = [0] * 26
for i in range(n):
	score[ord(s[i]) - ord('A')] += 1
mini = 10 ** 29
for i in range(k):
	mini = min(mini, score[i])
ans = mini * k
for i in range(k, 26):
	ans += score[i]
print(ans)


def char_frequency(str1):
	dict = {}
	for n in str1:
		keys = dict.keys()
		if n in keys:
			dict[n] += 1
		else:
			dict[n] = 1
	return dict
(n, k) = map(int, input().split())
alpha = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
s = input()
dick = char_frequency(s)
cnt = 0
mini = 1000000
for i in alpha:
	cnt += 1
	if i in dick.keys():
		mini = min(mini, dick[i])
	else:
		mini = 0
	if cnt == k:
		break
print(k * mini)


(n, k) = map(int, input().split())
s = input()
a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
temp = a[:k]
cl = []
for i in temp:
	cl.append(s.count(i))
cl.sort()
print(cl[0] * k)


from collections import Counter
(n, k) = [int(x) for x in input().split()]
lst = list(input())
st = set(lst)
if len(st) != k:
	print(0)
	exit()
cnt = Counter(lst)
x = cnt.most_common()[:-n - 1:-1]
print(x[0][1] * k)


(n, k) = map(int, input().split())
k1 = list(input())
k2 = []
l = [chr(i).upper() for i in range(97, 97 + k)]
if k == len(set(k1)):
	for i in l:
		k2.append(k1.count(i))
	print(min(k2) * k)
else:
	print(0)


(n, k) = map(int, input().split())
st1 = input()
m = k
l1 = list(map(chr, range(65, 91)))
p = 0
b = []
while p < k:
	b.append(st1.count(l1[p]))
	p = p + 1
print(min(b) * m)


mini = 1000000
alphabet = [0] * 26
(n, k) = map(int, input().split())
st = input()
for i in st:
	alphabet[ord(i) - 65] += 1
for i in range(k):
	mini = min(mini, alphabet[i])
print(mini * k)


def main():
	[n, k] = [int(_) for _ in input().split()]
	s = input()
	chars = {chr(ord('A') + i): 0 for i in range(k)}
	for i in range(n):
		chars[s[i]] += 1
	min_occurences = min(chars.values())
	print(min_occurences * k)
main()


(n, k) = map(int, input().split())
s = input()
l = list()
q = list()
w = set()
c = int(0)
m = int(0)
for i in range(len(s)):
	w.add(s[i])
	l.append(s[i])
if len(w) != k:
	print(0)
	exit()
l.sort()
for i in range(len(s) - 1):
	if l[i] == l[i + 1]:
		c += 1
	else:
		q.append(c + 1)
		c = 0
q.append(c + 1)
q.sort(reverse=True)
m = q[k - 1] * k
print(m)


from string import ascii_uppercase as ab
(n, k) = map(int, input().split())
s = input()
ans = min(map(s.count, ab[:k])) * k
print(ans)


import sys
import bisect
from collections import Counter
read_int = lambda : int(sys.stdin.readline())
read_ints = lambda : list(map(int, sys.stdin.readline().split()))
read_int_list = lambda : list(read_ints())
read = lambda : sys.stdin.readline().strip()
read_list = lambda : sys.stdin.readline().split()

def main():
	(n, k) = read_ints()
	s = read()
	d = Counter(s)
	res = k * min(d.values()) if len(d) == k else 0
	print(res)
main()


import sys
(n, k) = map(int, input().split())
s = input()
for i in range(1, k + 1):
	if chr(i + 64) in s == False:
		print('0')
		sys.exit
arr = []
for j in range(1, k + 1):
	t = 0
	for i in range(n):
		if s[i] == chr(64 + j):
			t += 1
	arr.append(t)
print(min(arr) * k)


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = 1
for tt in range(t):
	(n, k) = map(int, sys.stdin.readline().split(' '))
	s = str(input())
	ans = mod
	for i in range(65, 65 + k):
		ss = chr(i)
		ans = min(ans, s.count(ss))
	print(ans * k)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


(n, k) = map(int, input().split())
a = list(input())
g = [0] * k
for i in a:
	g[ord(i) - 65] += 1
print(k * min(g))


(n, k) = map(int, input().split())
s = input()
m = s.count('A')
for i in range(65, 65 + k):
	m = min(m, s.count(chr(i)))
print(m * k)


import string
(n, k) = map(int, input().split())
s = input()
letters = string.ascii_uppercase[:k]
st = set(s)
ans = 0
if len(st) == k:
	min_occurences = 100001
	for letter in st:
		cnt = s.count(letter)
		if cnt < min_occurences:
			min_occurences = cnt
	ans = min_occurences * k
print(ans)


(n, k) = map(int, input().rstrip().split(' '))
s = input().rstrip()
counter = [0] * k
for element in s:
	counter[ord(element) - ord('A')] += 1
result = min(counter) * k
for element in counter:
	if element == 0:
		result = 0
print(result)


(n, k) = map(int, input().split())
str = input()
a = [0] * k
for i in str:
	a[ord(i) - ord('A')] += 1
print(min(a) * k)


(length, letters) = [int(i) for i in input().split(' ')]
sequence = input()
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
record = length
for i in range(letters):
	current = 0
	for k in sequence:
		if k == ascii_uppercase[i]:
			current += 1
	if current == 0:
		record = 0
		break
	record = min(record, current)
print(record * letters)


import math
import bisect
import collections
import itertools
import string
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd, Counter as ctr
from bisect import bisect_left as bl, bisect_right as br
from itertools import permutations as pr, combinations as cb
from string import ascii_uppercase as a_up
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
p_inf = float('inf')
n_inf = float('-inf')

def mex(arr):
	nList = set(arr)
	mex = 0
	while mex in nList:
		mex += 1
	return mex

def results(arr, k):
	tmp = ctr(arr)
	aplha = list(a_up[:k])
	cnt = p_inf
	for i in aplha:
		try:
			cnt = min(tmp[i], cnt)
		except:
			return 0
	return cnt * k

def main():
	nk = seq()
	(n, k) = (nk[0], nk[1])
	s = strl()
	print(results(s, k))
main()


n = input().split()
k = int(n[1])
n = int(n[0])
s = input()
q = 100000
for i in range(ord('A'), ord('A') + k):
	m = s.count(chr(i))
	if m < q:
		q = m
print(q * k)


ta = []
(n, k) = list(map(int, input().split()))
p = list(input())
if len(set(p)) != k:
	print(0)
else:
	for item in list(set(p)):
		ta.append(p.count(item))
	l = min(ta)
	print(l * k)


import string
(a, b) = map(int, input().split())
c = input()
count1 = []
for i in string.ascii_uppercase[:b]:
	count1.append(c.count(i))
print(min(count1) * b)


(n, k) = map(int, input().split())
s = input()
alpha = [0] * 26
for i in s:
	alpha[ord(i) - ord('A')] += 1
print(min(alpha[:k]) * k)


(n, k) = input().split()
(n, k) = (int(n), int(k))
st = str(input())
ls = list()
for g in range(65, 65 + k):
	ls.append(st.count(chr(g)))
print(min(ls) * k)


m = 1000000
alphabetc = [0] * 26
(n, k) = map(int, input().split())
st = input()
for i in st:
	alphabetc[ord(i) - 65] += 1
for i in range(k):
	m = min(m, alphabetc[i])
print(m * k)


a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
(n, k) = map(int, input().split())
s = input()
l = []
for i in range(k):
	l.append(s.count(a[i]))
print(min(l) * k)


from collections import Counter
(n, k) = list(map(int, input().strip().split(' ')))
s = input()
c = dict(Counter(s))
ans = k * min(c.values())
for i in [chr(x) for x in range(65, 65 + k)]:
	if i not in c.keys():
		ans = 0
		break
print(ans)


(n, m) = map(int, input().split())
a = list(input())
b = list(set(a))
c = [0] * m
if len(b) != m:
	print(0)
else:
	d = dict(zip(b, c))
	for i in a:
		d[i] += 1
	e = list(d.values())
	e.sort()
	print(m * e[0])


(n, k) = map(int, input().split())
s = input()
t = set()
for i in range(k):
	t.add(s.count(chr(65 + i)))
print(min(t) * k)


s = input().split()
(n, k) = (int(s[0]), int(s[1]))
s = input()
mn = n
count = 0
for i in range(k):
	t = s.count(chr(65 + i))
	count += t
	if t < mn:
		mn = t
if mn != 0:
	print(mn * k + n - count)
else:
	print(0)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	(n, k) = LI()
	c = collections.Counter(S())
	r = inf
	for t in string.ascii_uppercase[:k]:
		if r > c[t]:
			r = c[t]
	return r * k
print(main())


import string

def code7():
	(n, k) = map(int, input().split())
	s = input()
	p = k
	m = 1111111
	for i in string.ascii_uppercase:
		m = min(m, s.count(i))
		k -= 1
		if k == 0:
			break
	print(m * p)
code7()


(n, k) = map(int, input().split())
s = input()
num = dict()
all1 = []
ans = 1000000000000
for i in range(65, 65 + k):
	all1.append(chr(i))
for i in range(n):
	if not s[i] in num:
		num[s[i]] = 1
	else:
		num[s[i]] += 1
for i in range(k):
	if all1[i] not in num:
		ans = 0
		break
	ans = min(ans, num[all1[i]])
print(ans * k)


d = {'1': 'A', '2': 'B', '3': 'C', '4': 'D', '5': 'E', '6': 'F', '7': 'G', '8': 'H', '9': 'I', '10': 'J', '11': 'K', '12': 'L', '13': 'M', '14': 'N', '15': 'O', '16': 'P', '17': 'Q', '18': 'R', '19': 'S', '20': 'T', '21': 'U', '22': 'V', '23': 'W', '24': 'X', '25': 'Y', '26': 'Z'}
(a, b) = input().split()
(a, b) = (int(a), int(b))
c = input()
h = 9999999
for i in range(b):
	if c.count(d[str(i + 1)]) < h:
		h = c.count(d[str(i + 1)])
else:
	print(h * b)


inn = input()
(n, k) = inn.split()
(n, k) = (int(n), int(k))
lett = []
for i in range(26):
	lett.append(0)
s = input()
for i in range(n):
	lett[ord(s[i]) - ord('A')] += 1
menor = lett[0]
for i in range(k):
	menor = min(menor, lett[i])
print(menor * k)


(n, k) = map(int, input().split())
s = input()
ss = set(s)
m = n
if len(ss) == k:
	for i in ss:
		l = s.count(i)
		if l < m:
			m = l
	print(m * k)
else:
	print(0)


(n, k) = map(int, input().split())
s = input()
ar = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
a = list(ar)
ar2 = []
for i in range(k):
	ar2.append(s.count(ar[i]))
print(min(ar2) * k)


(n, m) = map(int, input().split(' '))
L = list(input())
w = 65
D = []
for i in range(0, m):
	r = chr(w)
	p = L.count(r)
	D.append(p)
	w = w + 1
print(min(D) * m)


(n, k) = map(int, input().split(' '))
str_input = list(input().strip())

def count_fre(list_input, char):
	total_count = 0
	for i in list_input:
		if i == char:
			total_count += 1
		else:
			continue
	return total_count
dist_char = list(set(str_input))
list_count = []
if n > len(str_input):
	print('Wrong Input')
elif k > len(dist_char):
	print(0)
else:
	for i in dist_char:
		total_count = count_fre(str_input, i)
		list_count.append((i, total_count))
	list_count = sorted(list_count, key=lambda x: x[1], reverse=True)
	smallest_lenght = list_count[k - 1][1]
	print(smallest_lenght * k)


(n, k) = map(int, input().split())
s = input()
g = [0] * k
for i in s:
	g[ord(i) - 65] += 1
print(k * min(g))


(n, k) = map(int, input().split())
s = input()
c = [0] * k
for e in s:
	c[ord(e) - ord('A')] += 1
print(min(c) * k)


from collections import Counter
(n, k) = map(int, input().split())
x = input()
x = list(x)
if len(set(x)) < k:
	print(0)
else:
	(a, b) = Counter(x).most_common()[-1]
	print(b * k)


(size, frq) = map(int, input().split())
arr = input()
(count, i, low) = (0, 0, 10000000000)
brr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
while i < frq:
	count = arr.count(brr[i])
	if count == 0:
		print(0)
		exit()
	if count < low:
		low = count
	i = i + 1
print(frq * low)


(n, k) = map(int, input().split())
s = str(input())
alph = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
arr = [0] * 26
for i in range(n):
	arr[alph.index(s[i])] += 1
print(k * min(arr[0:k]))


n = [0] * 26
(a, b) = map(int, input().split())
c = input()
d = len(c)
f = 1000001
for i in range(a):
	e = ord(c[i]) - ord('A')
	n[e] += 1
for i in range(b):
	if f > n[i]:
		f = n[i]
print(f * b)


(n, m) = map(int, input().split())
mot = str(input())
tab = [0] * m
for e in mot:
	if 0 <= ord(e) - ord('A') < m:
		tab[ord(e) - ord('A')] += 1
print(min(tab) * m)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from bisect import bisect_right
(n, k) = map(int, input().split())
s = input()
ls = [0] * k
for i in s:
	var = ord(i) - ord('A')
	if var <= k - 1:
		ls[var] += 1
print(k * min(ls))


(n, k) = map(int, input().split())
s = input()
m = []
l = 0
c = []
for i in range(65, 65 + k):
	m.append(chr(i))
for j in m:
	z = s.count(j)
	if z == 0:
		l += 1
	else:
		c.append(z)
if l != 0:
	print(0)
else:
	print(min(c) * k)


(n, k) = (int(x) for x in input().split())
s = input()
a = [0] * k
for x in s:
	a[ord(x) - 65] += 1
print(min(a) * k)


d = {}
(n, m) = map(int, input().strip().split()[:2])
l = input()[:n]
k = 10 ** 7
for x in l:
	if x not in d:
		d[x] = 1
	else:
		d[x] += 1
if len(d) != m:
	print(0)
else:
	for x in d:
		k = min(d[x], k)
	print(k * m)


k = int(input().split()[1])
s = input()
print(k * min((s.count(chr(ord('A') + i)) for i in range(k))))


def separate_first_input(text):
	split_text = text.split(' ')
	total = int(split_text[0])
	last_letter = int(split_text[1])
	return (total, last_letter)

def get_all_chars_until(i):
	letters = []
	for k in range(97, i + 97):
		letters.append(chr(k).upper())
	return letters

def get_letter_frequency(letter, text):
	freq = 0
	for c in text:
		if c == letter:
			freq += 1
	return freq

def main():
	first_input = input()
	(total, last_letter) = separate_first_input(first_input)
	text = input()
	letters_array = get_all_chars_until(last_letter)
	min_value = total
	for letter in letters_array:
		freq = get_letter_frequency(letter, text)
		if freq < min_value:
			min_value = freq
	print(min_value * last_letter)
main()


(n, x) = map(int, input().split())
a = input()
print(x * min((a.count(chr(65 + i)) for i in range(x))))


(n, k) = map(int, input().split())
s1 = input()
l1 = []
for i in range(k):
	l1.append(s1.count(chr(i + 65)))
if len(l1) != k:
	print(0)
else:
	print(min(l1) * k)


t = list(map(int, input().split()))[1]
str = input()
res = len(str) // t
for i in range(t):
	res = min(res, str.count(chr(ord('A') + i)))
print(res * t)


x = input().split()
a = input()
b = int(x[1])
c = ''
L = []
s = ''
for i in range(b):
	s += chr(i + 65)
for i in range(len(s)):
	L.append(a.count(s[i]))
n = min(L)
n *= b
print(n)


(a, b) = map(int, input().split())
s = input()
m = 65 + b
r = []
k = list(s)
for i in range(65, m):
	r.append(s.count(chr(i)))
print(min(r) * b)


(n, k) = map(int, input().split())
s = input()
se = set(list(s))
l = []
for i in se:
	l.append(s.count(i))
if len(se) >= k:
	print(min(l) * k)
	exit(0)
print(0)


(n, k) = map(int, input().split(' '))
s = input()
l = []
a = 0
for i in range(k):
	l.append(s.count(chr(i + ord('A'))))
print(min(l) * k)


(x, y) = map(int, input().split())
A = input()
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
wanted = letters[:y]
L = []
c = A.count(wanted[0])
for i in wanted:
	if A.count(i) < c:
		c = A.count(i)
print(c * y)


(x, y) = map(int, input().split())
a = input()
d = {}
s = 0
for i in range(y):
	d[65 + i] = 0
	for j in range(x):
		if ord(a[j]) == 65 + i:
			d[65 + i] = d[65 + i] + 1
min1 = d[65]
for i in d:
	if d[i] < min1:
		min1 = d[i]
print(min1 * y)


(n, k) = map(int, input().split())
s = input()
mins = 10000000.0
for i in range(65, 65 + k):
	mins = min(mins, s.count(chr(i)))
print(k * mins)


(n, k) = map(int, input().split())
string = input()
dictionary = {}
for each_char in string:
	if dictionary.get(each_char):
		dictionary[each_char] += 1
	else:
		dictionary[each_char] = 1
values = dictionary.values()
if len(values) != k:
	ans = 0
else:
	ans = min(values) * k
print(ans)


(n, k) = [int(x) for x in input().split()]
s = input()
res = []
for i in range(k):
	res.append(s.count(chr(ord('A') + i)))
print(min(res) * k)


def mi():
	return list(map(int, input().split(' ')))
(n, m) = mi()
s = input()
ans = 1000000
for i in range(m):
	ans = min(ans, s.count(chr(65 + i)))
print(ans * m)


(n, k) = map(int, input().split())
s = input()
b = []
for i in range(k):
	b.append(s.count(chr(i + 65)))
print(min(b) * k)


import sys
import math
import bisect

def main():
	(n, m) = map(int, input().split())
	A = [0] * m
	for c in input():
		i = ord(c) - ord('A')
		A[i] += 1
	print(min(A) * m)
main()


(n, k) = map(int, input().split())
s = input()
c = 0
count = [0] * 26
for i in s:
	count[ord(i) - ord('A')] += 1
x = min(count[0:k])
print(x * k)


from collections import Counter
(n, k) = map(int, input().split())
a = list(input())
s = Counter(a)
res = 0
if len(s.keys()) == k:
	cur = s.values()
	cur = sorted(cur)
	res = cur[0] * k
print(res)


import sys
import string

def ria():
	return [int(i) for i in input().split()]
(n, k) = ria()
mp = {}
for i in string.ascii_uppercase[:k]:
	mp[i] = 0
for i in input():
	if i in mp:
		mp[i] += 1
print(min(mp.values()) * k)


(n, k) = map(int, input().split())
s = input()
d = [0 for _ in range(k)]
for i in s:
	d[ord(i) - ord('A')] += 1
print(min(d) * k)


(n, k) = map(int, input().split(' '))
ip = input()
seq = {}
i = 0
while i < n:
	if ord(ip[i]) < 65 + k:
		if ip[i] in seq:
			seq[ip[i]] += 1
		else:
			seq[ip[i]] = 1
	i += 1
vallist1 = sorted(seq.items(), key=lambda x: x[0])
vallist2 = sorted(seq.items(), key=lambda x: x[1])
length = len(seq)
if length == k:
	print(vallist2[0][1] * k)
else:
	print(0)


from collections import Counter

def func():
	(x, y) = map(int, input().split())
	n = input()
	d = dict()
	for i in n:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	if len(d) < y:
		print('0')
	else:
		print(min(d.values()) * y)
t = 1
for i in range(t):
	func()


(a, b) = map(int, input().split())
lis = []
s = input()
x = chr(64 + b)
if x in s:
	for i in range(1, b + 1):
		lis.append(s.count(chr(64 + i)))
	print(min(lis) * b)
else:
	print(0)


(n, k) = map(int, input().split())
s = input()
l = []
for i in range(26):
	l.append(0)
for i in s:
	l[ord(i) - 65] += 1
min = 1000000000
for i in range(k):
	if min > l[i]:
		min = l[i]
print(min * k)


import sys
import collections
(n, k) = input().split()
(n, k) = [int(n), int(k)]
a = input()
a = list(a)
m = set(a)
d = collections.Counter(a)
if len(m) < k:
	print('0')
else:
	ma = sys.maxsize
	for i in a:
		if ord(i) - 96 <= k and d[i] < ma:
			ma = d[i]
	print(ma * k)


def I():
	return map(int, input().split())
(n, k) = I()
s = input()
if len(set(s)) < k:
	print('0')
else:
	print(min((s.count(i) for i in set(s))) * len(set(s)))


(n, k) = [int(x) for x in input().split()]
s = list(input())
a = [0] * k
for i in range(n):
	a[ord(s[i]) - 65] += 1
print(min(a) * k)


from collections import defaultdict
d = defaultdict(lambda : 0)
(n, k) = map(int, input().split())
s = input()
for i in s:
	d[i] += 1
mini = d['A']
for i in range(66, 66 + k - 1):
	if d[chr(i)] < mini:
		mini = d[chr(i)]
print(mini * k)


(l, n) = [int(i) for i in input().split()]
s = input()
a = []
z = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for i in range(n):
	a.append(s.count(z[i]))
print(min(a) * len(a))


from sys import stdin
(n, k) = map(int, stdin.readline().split())
s = stdin.readline().strip()
cnt = [0 for _ in range(k)]
repeat = set()
i = 0
d = dict()
for u in s:
	if u not in repeat:
		repeat.add(u)
		d[u] = i
		cnt[i] += 1
		i += 1
	else:
		cnt[d[u]] += 1
print(min(cnt) * k)


(n, k) = map(int, input().split())
l = list(input())
ans1 = list(set(l[:]))
ans = []
if len(ans1) != k:
	print(0)
else:
	for i in range(len(ans1)):
		ans.append(l.count(ans1[i]))
	print(min(ans) * k)


from collections import Counter
(_, k) = map(int, input().split())
c = Counter(input())
print(0 if len(c) < k else k * min(c.values()))


(n, k) = map(int, input().split())
st = input()
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
lastLetter = k
counts = []
for letter in alphabet[0:lastLetter]:
	x = st.count(letter)
	counts.append(x)
print(min(counts) * k)


(n, k) = [int(s) for s in input().split(' ')]
s = input()
letters = set(list(s))
m = min([s.count(letter) for letter in letters])
if k == len(letters):
	print(m * k)
else:
	print(0)


from string import ascii_uppercase

def solve(n, k, s):
	c = {letter: 0 for (i, letter) in enumerate(ascii_uppercase[:k])}
	mini = 0
	for i in s:
		if i not in c:
			continue
		c[i] += 1
		mini = min(c.values())
	return k * mini

def main():
	(n, k) = list(map(int, input().split()))
	s = input()
	print(solve(n, k, s))
main()


from collections import defaultdict
D = defaultdict(int)
X = list(map(int, input().split()))
S = input()
for i in range(len(S)):
	D[S[i]] += 1
if len(D) != X[1]:
	print(0)
	exit()
print(min(D.values()) * X[1])


(n, k) = [int(i) for i in input().split()]
s = input()
m = n + 1
asc = 65
for i in range(1, k + 1):
	m = min(m, s.count(chr(asc)))
	asc += 1
if m != 0:
	print(m * k)
else:
	print('0')


from string import ascii_uppercase as abc
(n, k) = map(int, input().split())
s = input()
MIN = 10 ** 6
d = dict()
for i in range(k):
	d[abc[i]] = 0
for i in range(n):
	d[s[i]] += 1
for i in d.values():
	MIN = i if i < MIN else MIN
print(MIN * k)


(n, k) = list(map(int, input().split()))
s = input()
alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
a = dict([(lit, 0) for lit in alpha[:k]])
for i in range(n):
	a[s[i]] += 1
min_cnt = min(a.values())
print(min_cnt * k)


(a, b) = map(int, input().split())
c = input()
d = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
x = []
for i in range(b):
	g = c.count(d[i])
	x.append(g)
print(min(x) * b)


(n, k) = map(int, input().split())
c = [0] * k
for ch in input():
	p = ord(ch) - ord('A')
	c[p] += 1
print(min(c) * k)


[n, k] = [int(x) for x in input().split()]
s = input()
C = []
for i in range(k):
	C.append(s.count(chr(i + 65)))
print(k * min(C))


a = input()
a = list(map(int, a.split()))
b = input()
n = []
q = []
flag = 1
for i in range(a[1]):
	n.append(chr(65 + i))
for i in n:
	q.append(b.count(i))
for i in q:
	if i == '0':
		flag = 0
		print('0')
		break
if flag == 1:
	print(a[1] * min(q))


alf = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
(n, word) = map(int, input().split())
li = input()
li = list(li)
lib = {}

def main():
	minn = min(lib.values())
	print(minn * word)
for i in li:
	k = 1
	if i in lib.keys():
		k = lib[i] + 1
	small_lib = {i: k}
	lib.update(small_lib)
if len(lib.keys()) != word:
	print(0)
else:
	main()


from collections import Counter
(n, k) = map(int, input().split())
s = Counter(input()).most_common(k)
if len(s) == k:
	print(s[-1][1] * k)
else:
	print(0)


(a, b) = map(int, input().split())
s = str(input())
x = set(s)
l = list(x)
l2 = list(s)
l1 = len(l)
z = a
if b > len(x):
	print(0)
else:
	for i in range(l1):
		if l[i] in l2:
			y = l2.count(l[i])
			if y < z:
				z = y
	print(z * b)


(n, k) = map(int, input().split())
a = list(input())
b = list(set(a[:]))
if len(b) != k:
	print(0)
else:
	anss = []
	for i in range(len(b)):
		anss.append(a.count(b[i]))
	print(min(anss) * k)


from collections import Counter
from typing import Iterator

def get_num_input() -> Iterator[int]:
	return map(int, input().split())

def main() -> None:
	min_count: int
	(_, min_count) = get_num_input()
	mapping: Counter = Counter(input())
	length: int = len(mapping)
	print(length * min(mapping.values()) if length >= min_count else 0)
ONLY_ONCE: bool = True
for _ in range(1 if ONLY_ONCE else int(input())):
	main()


def solv(k, s):
	count = [0] * k
	for i in s:
		count[ord(i) - ord('A')] += 1
	mincount = min(count)
	return k * mincount
(n, k) = map(int, input().split())
s = input()
print(solv(k, s))


(n, k) = map(int, input().split())
alpha_dict = dict()
for i in input():
	alpha_dict[i] = alpha_dict.get(i, 0) + 1
if chr(64 + k) not in alpha_dict or len(alpha_dict) != k:
	print(0)
else:
	min_value = min(alpha_dict.values())
	print(min_value * k)


(n, k) = [int(x) for x in input().split()]
s = input()
ct = [0 for i in range(26)]
for i in range(len(s)):
	ct[ord(s[i]) - ord('A')] = ct[ord(s[i]) - ord('A')] + 1
flag = 1
for i in range(k):
	if ct[i] == 0:
		flag = 0
min = 100000.0
if flag == 1:
	for i in range(k):
		if ct[i] < min:
			min = ct[i]
	print(int(k * min))
else:
	print(0)


(n, k) = map(int, input().split())
s = input()
ords = [0] * 100
for t in s:
	ords[ord(t) - 65] += 1
print(min(ords[:k]) * k)


(n, k) = map(int, input().split())
p = list(input())
q = set(p)
q1 = set([chr(i).upper() for i in range(97, 97 + k)])
if q == q1:
	w = []
	for i in q:
		w.append(p.count(i))
	min = w[0]
	for i in w:
		if i < min:
			min = i
	print(min * len(q))
else:
	print('0')


(n, k) = map(int, input().split())
s = input()
characters = list(set(s))
if len(characters) < k:
	print(0)
else:
	count = [0] * len(characters)
	output = 0
	for i in range(len(characters)):
		count[i] = s.count(characters[i])
	count = sorted(count)
	print(count[0] * k)


(x, y) = [int(i) for i in input().split()]
z = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
a = input()
b = a.count('A')
for i in z[0:y]:
	c = a.count(i)
	if c < b:
		b = c
print(b * y)


(n, k) = map(int, input().split())
u = list(input())
s = [0] * k
c = ord('A')
for i in range(n):
	s[ord(u[i]) - c] += 1
print(min(s) * k)


(a, b) = [int(i) for i in input().split()]
S = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
L = input()
k = L.count('A')
for i in range(1, b):
	if L.count(S[i]) < k:
		k = L.count(S[i])
print(k * b)


(n, k) = map(int, input().lstrip().split())
text = input().lstrip()
alphaB = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
minnum = 999999999999
for i in range(k):
	num = text.count(alphaB[i])
	if num < minnum:
		minnum = num
print(minnum * k)


def ii():
	return int(input())

def ss():
	return [x for x in input()]

def si():
	return [int(x) for x in input().split()]

def mi():
	return map(int, input().split())
(a, b) = mi()
c = input()
s = dict()
for i in c:
	if i in s:
		s[i] += 1
	else:
		s[i] = 1
q = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
for i in range(b):
	if not q[i] in s:
		s[q[i]] = 0
print(min(list(s.values())) * b)


def do():
	import collections
	(n, k) = map(int, input().split())
	s = input()
	c = collections.Counter(s)
	l = c.most_common(n)
	if len(l) < k:
		print(0)
		return
	print(l[k - 1][1] * k)
do()


(n, k) = list(map(int, input().split()))
s = input()
a = [0] * 26
for i in s:
	a[ord(i) - ord('A')] += 1
ans = 100000000
for i in range(k):
	ans = min(ans, a[i])
print(ans * k)


(n, k) = map(int, input().split())
st = input()
print(k * min((st.count(chr(65 + i)) for i in range(k))))


(n, k) = list(map(int, input().split()))
count = [0] * k
for c in input():
	count[ord(c) - ord('A')] += 1
print(k * min(count))


from collections import Counter
(n, k) = map(int, input().split())
a = input()
c = Counter(a)
alphabets = [chr(x) for x in range(65, 65 + 26)]
answer = n
for alphabet in alphabets[:k]:
	try:
		answer = min(answer, c[alphabet])
	except:
		answer = 0
print(answer * k)


(n, k) = map(int, input().split())
s = input()
d = {chr(i + 65): 0 for i in range(26)}
for i in range(n):
	d[s[i]] += 1
mn = 1000000.0
q = 0
for e in d.keys():
	q += 1
	if d[e] < mn and q <= k:
		mn = d[e]
print(mn * k)


import sys
(n, k) = map(int, input().split())
count = {}
for c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ '[:k]:
	count[c] = 0
for i in range(n):
	ch = sys.stdin.read(1)
	if ch in count:
		count[ch] += 1
print(count[min(count, key=count.get)] * k)


(n, m) = list(map(int, input().split()))
st = input()
setst = list(set(st))
l = []
for i in range(len(setst)):
	l.append(st.count(setst[i]))
if len(l) == m:
	print(m * min(l))
else:
	print(0)


(n, m) = map(int, input().split())
a = input()
b = []
al = '-ABCDEFGHIJKLMNOPQRSTUVWXYZ'
count = 0
for i in range(1, m + 1):
	for j in range(len(a)):
		if a[j] == al[i]:
			count += 1
	b.append(count)
	count = 0
print(min(b) * m)


from collections import defaultdict
(n, k) = map(int, input().split())
s = input()
ds = defaultdict(int)
for x in s:
	ds[x] += 1
valids = [x for x in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[:k]]
m = 9999999999
for x in valids:
	m = min(m, ds[x])
print(m * k)


(n, k) = [int(x) for x in input().split()]
s = input()
res = 1
alph = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
counting_dict = {}
for i in alph[:k]:
	if i not in s:
		res = 0
for i in range(n):
	if s[i] not in counting_dict:
		counting_dict[s[i]] = 1
	else:
		counting_dict[s[i]] += 1
if res > 0:
	res = min(counting_dict.values()) * len(counting_dict)
print(res)


from collections import Counter
(n, k) = [int(__) for __ in input().strip().split()]
s = input().strip()
if len(set(s)) < k:
	print(0)
else:
	co = Counter(s)
	mi = len(s)
	for x in co:
		mi = min(mi, co[x])
	if mi == 0:
		print(0)
	else:
		ans = 0
		for x in co:
			if co[x] >= mi:
				ans += mi
		print(ans)


(N, K) = map(int, input().split())
L = list(input())
B = []
for i in range(K):
	X = chr(65 + i)
	count = 0
	for j in L:
		if j == X:
			count += 1
	B.append(count)
print(min(B) * K)


(n, k) = map(int, input().split())
x = input()
l = [0] * k
m = n
f = 0
for i in range(n):
	l[ord(x[i]) - 65] += 1
for i in range(k):
	if l[i] == 0:
		print('0')
		f = 1
		break
	elif l[i] != 0 and l[i] < m:
		m = l[i]
if f == 0:
	print(m * k)


(a, b) = map(int, input().split())
l = list(input())
d = []
for x in range(b):
	d.append(l.count(chr(65 + x)))
print(min(d) * b)


(n, k) = map(int, input().split())
a = input()
c = [0] * 26
for i in range(n):
	x = ord(a[i]) - 65
	c[x] += 1
x = []
for i in range(k):
	x.append(c[i])
print(min(x) * len(x))


(n, k) = map(int, input().split())
ar = list(input())
vals = [0 for _ in range(k)]
for i in range(n):
	vals[ord(ar[i]) - 65] += 1
print(min(vals) * k)


string = input().split(' ')
n = int(string[0])
k = int(string[1])
string = input()
chars = []
for i in range(k):
	chars.append(str(chr(65 + i)))
minimum = float('inf')
for item in chars:
	num = string.count(item)
	if num < minimum:
		minimum = num
print(str(minimum * k))


(n, k) = map(int, input().split(' '))
s = input()
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
first_k = alphabet[:k]
l = [0 for i in range(k)]
for i in range(n):
	l[first_k.index(s[i])] += 1
print(min(l) * k)


from collections import Counter
import math
ls = [int(i) for i in input().split(' ')]
n = ls[0]
k = ls[1]
word = input()
counts = Counter(word)
mn = 10000000
ch = ''
T = {}
for i in range(k):
	t = counts[chr(65 + i)]
	T[chr(65 + i)] = 0
	mn = min(mn, t)
	if mn == t:
		ch = chr(65 + i)
	if t == 0:
		print(0)
		exit()
res = ''
for x in word:
	if T[x] <= mn - 1:
		res += x
		T[x] += 1
print(len(res))


import string
(n, k) = map(int, input().split())
(s, t) = (input(), 999999)
for _ in range(k):
	t = min(t, s.count(string.ascii_uppercase[_]))
print(t * k)


(n, k) = map(int, input().split())
s = input()
letter = []
r = []
for l in s:
	if l not in letter:
		letter.append(l)
		r.append(s.count(l))
if len(r) == k:
	print(min(r) * k)
else:
	print(0)


from collections import *
(n, k) = map(int, input().split())
strt = ord('A')
ls = []
for i in range(k):
	ls.append(chr(strt + i))
d = dict(Counter(list(input())))
for i in ls:
	if i not in d:
		print(0)
		break
else:
	m = min(list(d.values()))
	print(m * k)


(n, k) = map(int, input().split())
s = input()
p = []
a = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
for i in range(k):
	c = 0
	for j in range(n):
		if a[i] == s[j]:
			c = c + 1
		else:
			continue
	p.append(c)
print(k * min(p))


(n, k) = [int(a) for a in input().split()]

def l(n):
	return ord(n) - ord('A')
s = [l(c) for c in input()]
an = [0] * k
for i in s:
	if i < k:
		an[i] += 1
ans = min(n, min(an))
print(ans * k)


def answer():
	alfie = 'abcdefghijklmnopqrstuvwxyz'.upper()
	a = [int(x) for x in input().split()]
	n = a[0]
	s = a[1]
	must = alfie[:s]
	t = list(input())
	m = 26
	z = []
	while m:
		z.append(0)
		m -= 1
	done = 0
	for x in must:
		if x not in t:
			print(0)
			done = 1
			break
	if not done:
		i = 0
		while i < len(t):
			z[alfie.index(t[i])] += 1
			i += 1
		z = [x for x in z if x != 0]
		ans = min(z) * len(z)
		print(ans)
answer()


from string import ascii_uppercase as a
inf = float('inf')
(n, k) = map(int, input().split())
s = input()
m = inf
for i in range(k):
	x = s.count(a[i])
	m = min(m, x)
print(m * k)


(n, k) = map(int, input().split())
string = input()
alphabet = [0] * k
for char in string:
	alphabet[ord(char) - 65] += 1
ans = alphabet[0]
for i in alphabet:
	ans = min(ans, i)
print(ans * k)


(a, b) = tuple(map(int, input().split()))
c = input()
alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
l = []
for i in range(b):
	l.append(c.count(alpha[i]))
print(min(l) * b)


(n, k) = map(int, input().split())
s = list(input())
a = ord('A')
cnt = [0] * k
for ch in s:
	cnt[ord(ch) - a] += 1
print(k * min(cnt))


from math import inf
(n, k) = map(int, input().split())
s = list(input())
c = set(s)
if len(c) != k:
	print(0)
else:
	t = inf
	for i in c:
		k = s.count(i)
		if k < t:
			t = k
	print(t * len(c))


(n, k) = map(int, input().split())
l = list(input())
li = []
for i in range(k):
	r = chr(65 + i)
	li.append(l.count(r))
m = min(li)
print(m * k)


(n, k) = map(int, input().split())
s = input()
s = list(s)
d = dict()
x = []
for i in s:
	d[i] = 0
	if i not in x:
		x.append(i)
for i in s:
	d[i] += 1
min = 10 ** 10
for i in s:
	if d[i] > 0 and d[i] < min:
		min = d[i]
if len(x) == k:
	print(min * k)
else:
	print(0)


import itertools
(n, k) = map(int, input().split())
s = list(input())
s.sort()
l = [chr(ord('A') + i) for i in range(26)]
cnt = [0] * k
for i in range(k):
	if l[i] in s:
		cnt[i] = s.count(l[i])
print(min(cnt) * k)


import collections
(n, k) = map(int, input().split())
s = input()
c = collections.Counter(s)
if len(c) < k:
	print(0)
else:
	print(min(c.values()) * k)


from collections import defaultdict as dd
(n, k) = [int(i) for i in input().split(' ')]
s = input()
d = dd(int)
for i in s:
	d[i] += 1
ans = 1 << 65
for i in range(k):
	ans = min(ans, d[chr(i + 65)])
print(k * ans)


(n, m) = map(int, input().split())
st = input()
d = {}
for n in st:
	keys = d.keys()
	if n in keys:
		d[n] += 1
	else:
		d[n] = 1
if len(d) < m:
	print('0')
else:
	res = min(d.values())
	print(res * m)


from collections import Counter
(n, k) = (int(x) for x in input().split())
letter_counts = Counter(input())
counts = [0] * 27
for (letter, count) in letter_counts.items():
	counts[ord(letter) - ord('A')] = count
print(min(counts[:k]) * k)


(n, k) = map(int, input().strip().split())
s = input()
temp = []
a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for i in a[:k]:
	if s.count(i) > 0:
		temp.append(s.count(i))
if len(temp) == k:
	print(min(temp) * k)
else:
	print(0)


(n, k) = map(int, input().split())
s = input()
a = [0] * 26
for i in range(n):
	a[ord(s[i]) - ord('A')] = a[ord(s[i]) - ord('A')] + 1
min1 = 9999999999999999
for i in range(k):
	if a[i] == 0:
		print(0)
		exit()
	if min1 > a[i]:
		min1 = a[i]
print(min1 * k)


from string import ascii_uppercase as upcase
(n, k) = [int(i) for i in input().split()[:2]]
s = input()[:n]
finding = upcase[:k]
found = {}
for c in s:
	if c in finding:
		found.setdefault(c, 0)
		found[c] += 1
if len(found.values()) < k:
	print(0)
else:
	print(min(found.values()) * k)


import sys
import os

def solve(s, k):
	occ = [0] * 26
	for i in range(len(s)):
		occ[ord(s[i]) - ord('A')] += 1
	result = None
	for i in range(k):
		if result is None:
			result = occ[i]
		else:
			result = min(result, occ[i])
	return result * k

def main():
	(n, k) = map(int, input().split())
	s = input()
	print(solve(s, k))
main()


n = [0] * 26
(a, b) = map(int, input().split())
c = input()
f = 1000001
for i in range(a):
	e = ord(c[i]) - ord('A')
	n[e] += 1
f = min(n[0:b])
print(f * b)


from collections import OrderedDict
from sys import stdin
(n, k) = [int(x) for x in stdin.readline().split()]
s = input()
di = {}
for i in s:
	if i in di:
		di[i] += 1
	else:
		di[i] = 1
a = di.values()
m = min(a)
st = set(list(s))
if len(st) == k:
	ans = ''
	print(m * k)
else:
	print(0)


(n, k) = map(int, input().split())
s = input()
a = list(map(ord, s))
for x in range(1, k + 1):
	if x + 64 not in a:
		flag = 0
		break
	else:
		flag = 1
if flag == 1:
	s = set(a)
	c = [a.count(i) for i in s]
	m = min(c)
	print(len(s) * m)
else:
	print(0)


(a, b) = map(int, input().split())
s = input()
c = [0] * b
for i in s:
	c[ord(i) - ord('A')] += 1
print(min(c) * b)


(n, m) = [int(x) for x in input().split()]
s = input()
ha = [0] * 26
for i in range(len(s)):
	ha[ord(s[i]) - 65] += 1
z = ha.count(0)
if 26 - z >= m:
	x = []
	for i in range(26):
		if ha[i] != 0:
			x.append(ha[i])
	if len(x) > m:
		xsort = sorted(x)
		c = xsort[len(x) - m] * m
	else:
		c = min(x) * m
else:
	c = 0
print(c)


(n, k) = map(int, input().split())
b = [0] * 26
for x in input():
	b[ord(x) - 65] += 1
print(min(b[:k]) * k)


(n, k) = [int(x) for x in input().split()]
dic = [0] * k
s = input()
for (i, c) in enumerate(s):
	dic[ord(c) - ord('A')] += 1
print(min(dic) * k)


(n, k) = input().split()
n = int(n)
k = int(k)
strs = input()
array = [0 for i in range(k)]
for i in strs:
	array[ord(i) - 65] += 1
ans = min(array) * k
print(ans)


(n, k) = map(int, input().split())
b = input()
d = dict()
for j in range(k):
	d[j + 65] = 0
p = 1000000000000
for j in range(n):
	d[ord(b[j])] += 1
for j in range(k):
	p = min(p, d[j + 65])
print(p * k)


(size, limit) = map(int, input().split(' '))
word = input()
alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
print(min([word.count(i) for i in alpha[:limit]]) * limit)


(n, m) = map(int, input().split())
k = input()
print(min([k.count(chr(65 + v)) for v in range(m)]) * m)


(n, k) = [int(x) for x in input().split()]
st = input()
d = {}
for letter in st:
	d[letter] = d.get(letter, 0) + 1
start = 'A'
timeslist = []
for i in range(k):
	times = d.get(start, 0)
	timeslist.append(times)
	start = chr(ord(start) + 1)
print(min(timeslist) * k)


from collections import Counter
(n, k) = map(int, input().split())
s = Counter(input() + ''.join((chr(i + ord('A')) for i in range(k))))
print((min(s.values()) - 1) * k)


from collections import Counter
(n, k) = list(map(int, input().split(' ')))
s = input()
q = set(s)
if len(q) != k:
	print(0)
else:
	c = Counter(s)
	a = list(c.values())
	w = min(a)
	print(w * k)


(a, b) = map(int, input().split())
text = input()
alp = 'abcdefghijklmnopqrstuvwxyz'.upper()
rez = []
for i in alp[:b]:
	rez.append(text.count(i))
print(min(rez) * b)


(n, k) = [int(x) for x in input().split()]
s = input()
value = [0] * k
for i in range(0, n):
	x = ord(s[i]) - 65
	value[x] += 1
m = min(value)
print(m * k)


from collections import Counter
(n, k) = map(int, input().split())
s = list(input())
s2 = Counter(s)
if len(s2.keys()) != k:
	print(0)
else:
	s3 = s2.values()
	s3 = sorted(s3)
	print(int(s3[0]) * k)


(n, k) = map(int, input().split())
s = input()
L = [0] * 26
for j in range(0, len(s)):
	L[ord(s[j]) - 65] = L[ord(s[j]) - 65] + 1
ans = 1000000007
for j in range(0, k):
	ans = min(ans, L[j])
ans = k * ans
print(ans)


from collections import defaultdict
(n, k) = map(int, input().split())
s = input()
A = defaultdict(int)
for v in s:
	A[ord(v) - ord('A')] += 1
Min = 100000
for h in range(k):
	Min = min(Min, A[h])
print(Min * k)


def main():
	(n, k) = map(int, input().split())
	l = [0] * (65 + k)
	for c in map(ord, input()):
		l[c] += 1
	print(k * min(l[65:]))
main()


(n, k) = list(map(int, input().split()))
s = input()
l = [0] * 300
for i in s:
	l[ord(i)] += 1
minl = 2000000000000000
for i in range(k):
	minl = min(minl, l[i + ord('A')])
print(minl * k)


def g(s1, l, a, k):
	if l == 65:
		a[k - 1] = s1.count(chr(l))
	else:
		a[k - 1] = s1.count(chr(l))
		g(s1, l - 1, a, k - 1)
(n, k) = [int(x) for x in input().split()]
s = str(input())
s1 = list(s)
l = 65 + k - 1
a = []
for i in range(0, k):
	a.append(0)
g(s1, l, a, k)
print(min(a) * k)


(n, k) = map(int, input().split())
l = list(input())
w = []
q = []
alpha = 'A'
for i in range(0, k):
	w.append(alpha)
	alpha = chr(ord(alpha) + 1)
for i in range(len(w)):
	s = l.count(w[i])
	q.append(s)
y = min(q)
t = y * k
print(t)


import sys
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
mod = 10 ** 9 + 7
(n, k) = [int(i) for i in input().split()]
s = input()
a = [0] * 26
for i in s:
	temp = ord(i) - ord('A')
	a[temp] += 1
ans = 0
temp = []
for i in range(k):
	temp.append(a[i])
final = min(temp)
if final == 0:
	print(0)
else:
	print(final * k)


(m, n) = map(int, input().split())
s = input()
q = 64
ar = []
for i in range(65, n + 65):
	ar.append(s.count(chr(i)))
r = min(ar)
print(r * n)


(n, k) = list(map(int, input().split()))
s = input()
f = 0
a = []
ch = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
mych = ch[:k]
for i in range(len(mych)):
	a.append(s.count(mych[i]))
	if mych[i] not in s:
		f = 1
if f == 1:
	print(0)
else:
	print(min(a) * k)


from collections import Counter
(n, k) = input().strip().split()
(n, k) = (int(n), int(k))
s = input().strip()
cc = Counter(s)
if len(cc.keys()) == k:
	print(cc.most_common()[-1][1] * k)
else:
	print(0)


(n, k) = map(int, input().split())
a = str(input())
d = {}
for i in a:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
if len(d) != k:
	print(0)
else:
	mini = 1000000
	for j in d:
		if d[j] < mini:
			mini = d[j]
	print(mini * len(d))


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_int = lambda : int(sys.stdin.readline().strip())
pt = lambda x: sys.stdout.write(str(x))
from collections import defaultdict
(n, k) = get_list()
s = get_string()
d = defaultdict(int)
alphabet = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')[:k]
if len(set(s)) == k:
	for i in s:
		d[i] += 1
	m = min(d.values())
	print(m * k)
else:
	print(0)


(n, k) = map(int, input().split())
line = input()
line_2 = [0] * 30
for elem in line:
	line_2[ord(elem) - 65] += 1
m = 10 ** 5
for i in range(k):
	m = min(m, line_2[i])
print(m * k)


(n, k) = list(map(int, input().split()))
a = input()
b = {}
m = 100000000
for i in range(len(a)):
	if a[i] not in b:
		b[a[i]] = 1
	else:
		b[a[i]] += 1
c = []
for i in b:
	c.append(b[i])
if len(b) >= k:
	print(min(c) * k)
else:
	print(0)


(a, b) = map(int, input().split())
c = input()
d = 0
n = [0] * 26
for i in range(a):
	d = ord(c[i]) - ord('A')
	n[d] += 1
c = min(n[0:b])
print(c * b)


def counterar(string, letters, k):
	counter = []
	for a in range(k):
		counter.append(0)
	for l in range(len(string)):
		for a in range(k):
			letter = letters[a]
			if string[l] == letter:
				counter[a] += 1
	return counter
values = input()
(n, k) = values.split()
n = int(n)
k = int(k)
string = input()
letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
counter = counterar(string, letters, k)
existe = True
for d in range(len(counter)):
	if existe and counter[d] == 0:
		existe = False
		print(0)
maintainer = counter[0]
i = 0
maximo = 0
for l in range(len(counter)):
	if maximo < counter[l]:
		maximo = counter[l]
minimo = maximo
for l in range(len(counter)):
	if minimo > counter[l]:
		minimo = counter[l]
if existe:
	print(minimo * k)


(n, k) = input().split()
n = int(n)
k = int(k)
s = input()
a = []
for x in range(n):
	if s[x] not in a:
		a = a + [s[x]]
freq = []
if k == len(a):
	for i in a:
		q = 0
		for x in range(n):
			if i == s[x]:
				q = q + 1
		freq = freq + [q]
	print(min(freq) * k)
else:
	print(0)


a = [chr(i).upper() for i in range(97, 123)]
(n, k) = map(int, input().split())
s = input()
m = 1100000000000000
if a[k - 1] in s:
	for i in range(k):
		m = min(m, s.count(a[i]))
	print(m * k)
else:
	print(str(0))


(n, k) = map(int, input().split())
a = list(input())
d = {}
for i in a:
	d[i] = d.get(i, 0) + 1
r = sorted(list(d.values()))
ans = 0
m = len(r)
if m < k:
	print(0)
else:
	print(r[0] * k)


from collections import Counter
(n, k) = [int(i) for i in input().split()]
s = input()
d = dict(Counter(s))
m = list(d.values())
if len(d) < k:
	print(0)
else:
	print(min(m) * len(d))


(n, k) = map(int, input().split())
s = input()
cnt = [0] * k
for i in range(len(s)):
	cnt[ord(s[i]) - ord('A')] += 1
res = 1000000
for i in range(k):
	res = min(res, cnt[i])
print(k * res)


(n, k) = list(map(int, input().split(' ')))
s = input()
from collections import Counter
d = Counter(s)
if len(d) < k:
	print(0)
elif len(d) == k:
	ans = min([d[x] for x in d])
	print(ans * k)


(m, n) = input().split(' ')
n = int(n)
sentence = input()
temp = 1000000000000000000
alphabet = [chr(x) for x in range(65, 65 + n)]
for a in alphabet:
	min_a = sentence.count(a)
	if min_a < temp:
		temp = min_a
result = temp * n
print(result)


import sys
input = sys.stdin.readline
import bisect
l = input().split()
n = int(l[0])
k = int(l[1])
hashi = dict()
s = input()
for i in range(k):
	hashi[chr(65 + i)] = 0
for i in range(n):
	if s[i] in hashi:
		hashi[s[i]] += 1
	else:
		hashi[s[i]] = 1
mina = 10 ** 18
for i in hashi:
	mina = min(mina, hashi[i])
print(mina * k)


import string
t = input().split()
(n, k) = (int(t[0]), int(t[1]))
s = input()
alphabet = list(string.ascii_uppercase)
mini = n
for i in range(k):
	occ = s.count(alphabet[i])
	if mini > occ:
		mini = occ
print(mini * k)


def solve():
	(n, k) = [int(x) for x in input().split()]
	s = input()
	a = [chr(x) for x in range(ord('A'), ord('Z') + 1)]
	return min((s.count(a[i]) for i in range(k))) * k
print(solve())


from collections import defaultdict

def fun(string, n):
	char_freq = defaultdict(int)
	for char in string:
		char_freq[char] += 1
	return 0 if len(char_freq.keys()) < n else min(char_freq.values()) * n
(_, n) = tuple(map(int, input().split()))
string = input()
print(fun(string, n))


(n, k) = map(int, input().split())
s = input()
z = 0
for i in range(65, 65 + k):
	if chr(i) in s:
		continue
	else:
		z = 1
		break
if z == 1:
	print(0)
else:
	m = n
	s2 = list(s)
	for i in range(65, 65 + k):
		x = s2.count(chr(i))
		if x < m:
			m = x
	print(k * m)


def position(c):
	return ord(c) - ord('A')

def letter(i):
	return chr(i + ord('A'))
from collections import Counter
n = list(map(int, input().split()))
k = n[1]
n = n[0]
s = input()
freq = Counter(s)
min_freq = 9999999
for i in range(k):
	f = freq.get(letter(i))
	if f == None:
		print(0)
		exit(0)
	if f < min_freq:
		min_freq = f
print(min_freq * k)


MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(n, k) = I()
s = input()
a = [0] * 26
for i in s:
	a[ord(i) - 65] += 1
print(min(a[:k]) * k)


(n, k) = list(map(int, input().split()))
s = input()
d = {}
for c in s:
	d[c] = d.get(c, 0) + 1
m = 10 ** 9
for i in range(k):
	letter = chr(ord('A') + i)
	occurance = 0
	if letter in d:
		occurance = d[letter]
	m = min(m, occurance)
print(m * k)


(n, k) = map(int, input().split())
s = input()
l = [chr(65 + i) for i in range(k)]
s = list(s)
s.sort()
f = 0
for i in range(len(s)):
	if s[i] not in l:
		print(0)
		f = 1
		break
m = []
if f == 0:
	for i in range(len(l)):
		m.append(s.count(l[i]))
	print(k * min(m))


mn = input().split()
m = int(mn[0])
n = int(mn[1])
s = input().strip()
t = []
p = [chr(i) for i in range(ord('A'), ord('Z') + 1)]
t = p[0:n]
for x in t:
	if x not in s:
		print('0')
		exit()
u = dict()
for x in t:
	u[x] = 0
for x in s:
	if x in t:
		u[x] += 1
key_min = min(u.keys(), key=lambda k: u[k])
print(u[key_min] * n)


(N, K) = list(map(int, input().split()))
S = input().lower()
Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
Alpha_K = Alpha[0:K]
List_sub = []
Flag = True
for i in Alpha_K:
	if S.count(i) >= 1:
		Flag = True
		List_sub.append(S.count(i))
	else:
		Flag = False
		break
if Flag:
	print(min(List_sub) * K)
else:
	print(0)


(n, m) = map(int, input().split())
s = input()
v = m * [0]
for i in range(n):
	v[ord(s[i]) % ord('A')] += 1
Min = v[0]
for i in range(1, m):
	Min = min(Min, v[i])
print(Min * m)


(n, k) = map(int, input().split())
t = [0] * k
for i in input():
	t[ord(i) - 65] += 1
print(min(t) * k)


(n, m) = map(int, input().split())
a = input()
b = [0] * 26
for i in a:
	for j in range(65, 91):
		if ord(i) == j:
			b[j - 65] += 1
p = min(b[:m])
print(p * m)


(n, k) = map(int, input().split())
d = [0] * k
for c in input():
	d[ord(c) - ord('A')] += 1
print(min(d) * k)


NK = list(map(int, input().rstrip().split()))
N = NK[0]
K = NK[1]
letter = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
string = input().rstrip()
letter_num = []
for i in range(K):
	letter_num.append(string.count(letter[i]))
print(min(letter_num) * K)


(n, k) = map(int, input().split())
s = input()
ans = 1000000000000
for i in range(k):
	ans = min(s.count(chr(65 + i)), ans)
print(ans * k)


import string
(n, k) = list(map(int, input().split(' ')))
word = input()
letters = string.ascii_uppercase[:k]
if all(map(lambda x: x in word, letters)):
	occurences = {}
	for letter in letters:
		occurences[letter] = len(list(filter(lambda x: x == letter, word)))
	print(min(occurences.values()) * k)
else:
	print(0)


(n, k) = map(int, input().split())
s = input()
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
mins = 1000000.0 + 1
for i in range(k):
	mins = min(mins, s.count(alphabet[i]))
print(mins * k)


(n, k) = map(int, input().split())
s = input()
count = [0 for _ in range(k)]
for c in s:
	count[ord(c) - ord('A')] += 1
print(min(count) * k)


(a, b) = map(int, input().split())
s = input()
print(b * min((s.count(chr(65 + i)) for i in range(b))))


s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
(n, k) = map(int, input().split())
ss = input()
j = 10 ** 9
y = True
for i in range(k):
	o = ss.count(s[i])
	if o < j:
		if o == 0:
			y = False
			break
		else:
			j = o
if y == True:
	print(j * k)
else:
	print(0)


(n, k) = map(int, input().split())
st = input()
d = dict()
for i in st:
	if d.get(i, None):
		d[i] += 1
	else:
		d[i] = 1
if len(d.keys()) != k:
	print(0)
else:
	print(k * min(d.values()))


(n, k) = map(int, input().split())
s = input()
l = []
s1 = set(s)
if len(s1) != k:
	print(0)
else:
	d = {}
	for i in range(k):
		d[chr(65 + i)] = 0
	for i in d.keys():
		d[i] = s.count(i)
		l.append(d[i])
	print(min(l) * k)


from collections import Counter
(n, k) = list(map(int, input().split()))
s = input()
temp = [chr(64 + i) for i in range(1, k + 1)]
c = Counter(s)
for i in temp:
	if i not in s:
		print(0)
		break
else:
	print(min(c.values()) * k)


from math import *
from collections import *
import sys
sys.setrecursionlimit(10 ** 9)
(n, k) = map(int, input().split())
s = input()
c = Counter(s)
m = 10 ** 6
for i in range(k):
	ind = chr(i + 65)
	if ind not in c:
		m = 0
	else:
		m = min(m, c[ind])
print(m * k)


from collections import Counter
(n, k) = map(int, input().split())
s = input()
a = set(s)
if len(a) != k:
	print(0)
else:
	l = []
	c = Counter(s)
	for (i, items) in c.items():
		l.append(items)
	print(min(l) * k)


n = list(map(int, input().strip().split()))
q = input().strip()
a = [0] * n[1]
for i in q:
	a[ord(i) - 65] = a[ord(i) - 65] + 1
print(min(a) * n[1])


(n, k) = map(int, input().split())
s = list(input())
count = 100000
for i in set(s):
	if s.count(i) < count:
		count = s.count(i)
print(0 if len(set(s)) < k else k * count)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10 ** 5)
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
(n, k) = map(int, input().split())
s = input()
hash = defaultdict(int)
mini = inf
seti = set()
for i in s:
	if ord(i) - ord('A') < k:
		seti.add(i)
		hash[i] += 1
if len(seti) != k:
	print(0)
	exit()
for i in hash:
	mini = min(hash[i], mini)
print(mini * k)


from collections import defaultdict
(n, k) = [int(x) for x in input().split()]
s = input()
freq = defaultdict(lambda : 0)
for c in s:
	freq[c] += 1
minimum = 10 ** 9
for i in range(65, 65 + k):
	minimum = min(minimum, freq[chr(i)])
print(minimum * k)


def solve():
	(n, m) = map(int, input().split())
	s = input()
	set_s = set(s)
	if len(set_s) != m:
		print(0)
		return
	count = 100000000000.0
	for i in set_s:
		count = min(count, s.count(i))
	print(len(set_s) * count)
solve()


def mergeSort(arr):
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L)
		mergeSort(R)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if L[i] < R[j]:
				arr[k] = L[i]
				i += 1
			else:
				arr[k] = R[j]
				j += 1
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1
	return arr
a = input().split()
n = int(a[0])
k = int(a[1])
s = input()
a = [0] * k
for i in range(n):
	a[ord(s[i]) - 65] += 1
a = mergeSort(a)
print(a[0] * k)


import sys
(N, K) = map(int, sys.stdin.readline().strip().split())
string = sys.stdin.readline().strip()
from collections import defaultdict
appearance = defaultdict(int)
for ch in string:
	appearance[ch] += 1
min = 1000000000.0
for (key, val) in appearance.items():
	if min > val:
		min = val
if len(appearance) < K:
	print(0)
else:
	print(min * len(appearance))


config = input()
n = int(config.split(' ')[0])
k = int(config.split(' ')[1])
entrada = input()
alphabet = [0] * k
i = 0
while i < len(entrada):
	l = ord(entrada[i]) - ord('A')
	if l < k:
		alphabet[l] = alphabet[l] + 1
	i = i + 1
result = n
i = 0
while i < k:
	result = min(result, alphabet[i])
	i = i + 1
print(result * k)


(n, k) = (int(x) for x in input().split())
s = input()
a = [0 for i in range(k)]
for x in s:
	a[ord(x) - 65] += 1
count = 0
for i in range(len(a)):
	if a[i] != 0:
		count += 1
print(min(a) * count)


entrada = input()
entrada = entrada.split()
n = int(entrada[0])
k = int(entrada[-1])
ocorrencias = []
for i in range(k):
	ocorrencias.append(0)
s = input()
s = list(s)
maximo = 0
for i in range(len(s)):
	ocorrencias[ord(s[i]) - 65] += 1
	if ocorrencias[ord(s[i]) - 65] > maximo:
		maximo += 1
maior = 0
for i in range(maximo):
	atual = 0
	j = i + 1
	for a in ocorrencias:
		if a >= j:
			atual += j
		else:
			atual = 0
			break
	if atual > maior:
		maior = atual
print(maior)


(n, k) = [int(i) for i in input().split()]
s = input()
a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
res = []
for i in a[:k]:
	res.append(s.count(i))
print(min(res) * len(res))


def mi():
	return map(int, input().split())
(n, k) = mi()
s = list(input())
c = [0] * k
ot = 0
for i in range(n):
	s[i] = ord(s[i]) - 65
	if s[i] < k:
		c[s[i]] += 1
	if s[i] > k:
		ot += 1
if min(c) == 0:
	print(0)
else:
	print(min(c) * k + ot)


gi = lambda : list(map(int, input().split()))
(n, k) = gi()
s = list(input())
alph = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
print(min([s.count(e) for e in alph[:k]]) * k)


(n, k) = map(int, input().split())
l = list(input())[:n]
t = list(set(l))
a = []
if len(t) == k:
	for i in t:
		a.append(l.count(i))
	print(min(a) * k)
else:
	print(0)


(n, k) = map(int, input().split())
m = list(str(input()))
c = 0
f = 0
s = []
p = []
l = set(m)
for i in l:
	c = c + 1
if c != k:
	print('0')
else:
	for i in m:
		s.append(ord(i))
	g = set(s)
	for i in g:
		p.append(s.count(i))
	d = min(p)
	for i in range(len(p)):
		f = f + d
	print(f)


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	(n, k) = map(int, input().split())
	s = input()
	m = {}
	for i in range(65, 65 + k):
		m[chr(i)] = 0
	for i in range(n):
		if s[i] in m:
			m[s[i]] += 1
	ans = min(m.values()) * len(m.keys())
	print(ans)
t = 1
for _ in range(t):
	main()


a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
(n, k) = input().split()
n = int(n)
k = int(k)
s = str(input())
c = 0
c1 = 0
b = []
for i in range(k):
	c = s.count(a[i])
	b.append(c)
print(min(b) * k)


kek = input().split()
(n, k) = (int(kek[0]), int(kek[1]))
s = input()
slovar = set(s)
if len(slovar) < k:
	print('0')
else:
	slovar = dict(([i, 0] for i in slovar))
	for i in s:
		slovar[i] += 1
	minimum = min(slovar.values())
	print(minimum * k)


(n, k) = map(int, input().split())
s = input()
s = [ord(c) - 65 for c in s]
menor = s.count(0)
for i in range(1, k):
	occur = s.count(i)
	if occur < menor:
		menor = occur
m = sum((v > k for v in s)) + menor * k
print(m)


(n, k) = [int(i) for i in input().split()]
s = input()
a = []
for i in range(26):
	a.append(0)
for i in s:
	a[ord(i) - 65] += 1
m = n
for i in range(k):
	if a[i] < m:
		m = a[i]
print(k * m)


(n, k) = map(int, input().split())
s = input()
alth = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ai = [0] * 26
for i in s:
	ai[alth.find(i)] += 1
print(min(ai[:k]) * k)


from sys import stdin
from os import getenv
if getenv('ACM_ENV') == 'local':
	stdin = open('input.txt', 'r')
(n, k) = [int(x) for x in stdin.readline().split(' ')]
s = stdin.readline().strip()
chars = [0 for i in range(k)]
for c in s:
	chars[ord(c) - ord('A')] += 1
m = n
for c in chars:
	m = min(c, m)
print(m * k)


(n, k) = map(int, input().split())
l = list(map(str, input().strip()))
s = list(set(l))
temp = []
if len(s) != k:
	print(0)
else:
	for i in s:
		c = l.count(i)
		temp.append(c)
	temp.sort()
	print(k * temp[0])


from collections import Counter
(n, k) = list(map(int, input().split()))
s = input()
letters = list(s)
c = dict(Counter(letters))
if len(c) < k:
	print(0)
else:
	print(k * min(c.values()))


([n, k], s, c) = (list(map(int, input().split(' '))), input(), 10 ** 6)
for i in range(k):
	c = min(s.count(chr(i + 65)), c)
print(c * k)


s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
(n, k) = map(int, input().split())
ss = input()
maxx = 0
a = [0] * 26
for i in range(n):
	if s.find(ss[i]) < k:
		a[s.find(ss[i])] += 1
print(min(a[0:k]) * k)


def ravenstvo(s, k):
	a = [0] * 27
	for i in range(len(s)):
		a[ord(s[i]) - ord('A')] += 1
	mx = 1000000
	for i in range(k):
		mx = min(mx, a[i])
	return mx * k
(n, K) = [int(i) for i in input().split()]
t = input()
print(ravenstvo(t, K))


(n, k) = map(int, input().split())
string = input()
str1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
dic = {str1[i]: string.count(str1[i]) for i in range(k)}
minFre = min(dic.values())
print(minFre * k)


def check(enter, k):
	dead = []
	l_dict = {}
	for i in range(len(enter)):
		if enter[i] not in dead:
			l_dict[enter[i]] = 0
			l_dict[enter[i]] += 1
			dead.append(enter[i])
		else:
			l_dict[enter[i]] += 1
	check_len = len(l_dict.keys())
	if check_len < k:
		return 0
	a = min(l_dict.values())
	return a * k
n = input().split()
enter = input()
k = int(n[1])
print(check(enter, k))


from string import ascii_uppercase as alphabet
(n, k) = map(int, input().split())
s = input()
letter_count = [s.count(alphabet[i]) for i in range(0, k)]
print(min(letter_count) * k)


from collections import defaultdict
(n, k) = map(int, input().split())
s = list(input())
dic = defaultdict(lambda : 0)
for i in s:
	dic[i] += 1
print(0 if len(dic) < k else k * min(dic.values()))


(n, k) = [int(x) for x in input().split()]
s = input()
all_letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
frequencies = [0] * k
letter_to_number = {all_letters[i]: i for i in range(k)}
for i in range(n):
	pos = letter_to_number[s[i]]
	frequencies[pos] += 1
print(min(frequencies) * k)


(n, k) = map(int, input().strip().split())
s = input()
c = 10000000000
h = [0] * 26
for i in s:
	h[ord(i) - 65] += 1
for i in range(k):
	c = min(c, h[i])
print(k * c)


(n, k) = [int(x) for x in input().split()]
s = input()
alpha = {}
for val in s:
	if val not in alpha.keys():
		alpha[val] = 1
	else:
		alpha[val] += 1
if len(alpha) < k:
	print(0)
else:
	print(min(alpha.values()) * k)


from string import ascii_uppercase
(n, k) = map(int, input().split())
(s, ans) = (input(), 1000000000.0)
for i in ascii_uppercase[:k]:
	ans = min(ans, s.count(i))
print(ans * k)


(x, y) = map(int, input().split())
letters = list(input())
setters = len(set(letters))
setter = set(letters)
if setters < y:
	print(0)
	exit(0)
ans = []
for letter in setter:
	ans.append(letters.count(letter))
minx = min(ans)
print(minx * y)


from collections import Counter
import string
A = [i for i in string.ascii_uppercase]
(a, k) = map(int, input().split())
z = input()
p = sorted(list(set(z)))
B = A[:k]
if p == B:
	a = dict(Counter(z))
	b = min(a.items(), key=lambda x: x[1])[1]
	print(len(p) * b)
else:
	print(0)


l = [0 for i in range(30)]
k = int(input().split()[1])
s = input()
for c in s:
	l[ord(c) - 65] += 1
print(min(l[:k]) * k)


from collections import defaultdict
INF = 200000.0
(_, k) = map(int, input().split())
aa = [0] * k
for s in input():
	idx = ord(s) - ord('A')
	if idx < k:
		aa[idx] += 1
mn = INF
for a in aa:
	mn = min(mn, a)
print(mn * k)


(n, k) = map(int, input().split())
s1 = input()
count = [0 for i in range(k)]
for i in s1:
	temp = ord(i) - 65
	if temp < k:
		count[temp] += 1
print(min(count) * k)


a = [int(x) for x in input().split()]
n = a[0]
k = a[1]
s = input()
d = {}
for ch in s:
	if ch in d:
		d[ch] += 1
	else:
		d[ch] = 1
min = min(d.values())
if len(d) == k:
	print(min * k)
else:
	print(0)


(n, m) = map(int, input().split())
s = list(input())
fre = [0] * 26
for i in range(n):
	fre[ord(s[i]) - ord('A')] += 1
ans = min(fre[:m]) * m
print(ans)


from collections import Counter
(n, k) = map(int, input().split())
s = Counter(input())
co = float('inf')
for i in range(k):
	try:
		co = min(co, s[chr(65 + i)])
	except:
		co = 0
print(co * k)


(n, k) = map(int, input().split())
all_freq = {}
s = str(input())
for i in range(k):
	all_freq[chr(i + 65)] = 0
for i in s:
	if i in all_freq:
		all_freq[i] += 1
	else:
		all_freq[i] = 1
res = min(all_freq, key=all_freq.get)
print(all_freq.get(res) * k)


(n, k) = input().split()
n = int(n)
k = int(k)
string = input()
alfabeto = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
cont = []
for i in range(k):
	cont.append(0)
for i in range(n):
	achei = False
	s = string[i]
	alfa = 0
	while achei == False:
		if s == alfabeto[alfa]:
			cont[alfa] += 1
			achei = True
		alfa += 1
min = cont[0]
for i in range(1, k):
	if cont[i] < min:
		min = cont[i]
print(k * min)


para = list(map(int, input().split()))
n = int(para[0])
k = int(para[1])
s = input()
track = [0] * k

def even(track):
	for i in range(len(track) - 1):
		if track[i] != track[i + 1]:
			return False
	return True
for i in s:
	track[ord(i) - 65] += 1
track = sorted(track)
print(track[0] * len(track))


from collections import Counter

def equality(s, n, k):
	if s is None:
		return 0
	unq = set(s)
	if len(unq) != k:
		return 0
	vl = list(Counter(s).values())
	minCount = min(vl)
	for i in range(k):
		minCount = min(vl[i], minCount)
	minCount *= k
	return minCount
(n, k) = map(int, input().split())
equal = list(str(input()))
print(equality(equal, n, k))


(n_letters, first_k_letters) = input().split()
sequence_of_letters = input()
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
count_letters = [0] * int(first_k_letters)
for letter in sequence_of_letters:
	for (idx, position) in enumerate(alphabet):
		if letter == position:
			count_letters[idx] += 1
			break
minimum_letters = min(count_letters)
print(minimum_letters * int(first_k_letters))


(n, k) = map(int, input().split())
s = [chr(i) for i in range(65, 91)]
d = input()
r = []
for i in range(k):
	a = d.count(s[i])
	r.append(a)
print(min(r) * k)


(n, k) = map(int, input().split())
s = input()
bu = [0] * 1000
for i in range(len(s)):
	bu[ord(s[i]) - ord('A')] += 1
mini = 1000000
for i in range(k):
	mini = min(mini, bu[i])
print(mini * k)


(n, k) = map(int, input().split())
s = input()
a = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
b = [0] * 26
for i in range(n):
	if s[i] == 'A':
		b[0] += 1
	elif s[i] == 'B':
		b[1] += 1
	elif s[i] == 'C':
		b[2] += 1
	elif s[i] == 'D':
		b[3] += 1
	elif s[i] == 'E':
		b[4] += 1
	elif s[i] == 'F':
		b[5] += 1
	elif s[i] == 'G':
		b[6] += 1
	elif s[i] == 'H':
		b[7] += 1
	elif s[i] == 'I':
		b[8] += 1
	elif s[i] == 'J':
		b[9] += 1
	elif s[i] == 'K':
		b[10] += 1
	elif s[i] == 'L':
		b[11] += 1
	elif s[i] == 'M':
		b[12] += 1
	elif s[i] == 'N':
		b[13] += 1
	elif s[i] == 'O':
		b[14] += 1
	elif s[i] == 'P':
		b[15] += 1
	elif s[i] == 'Q':
		b[16] += 1
	elif s[i] == 'R':
		b[17] += 1
	elif s[i] == 'S':
		b[18] += 1
	elif s[i] == 'T':
		b[19] += 1
	elif s[i] == 'U':
		b[20] += 1
	elif s[i] == 'V':
		b[21] += 1
	elif s[i] == 'W':
		b[22] += 1
	elif s[i] == 'X':
		b[23] += 1
	elif s[i] == 'Y':
		b[24] += 1
	elif s[i] == 'Z':
		b[25] += 1
t = True
i = 0
m = 10000000
while i < k:
	if b[i] > 0:
		m = min(b[i], m)
		i += 1
	else:
		t = False
		break
if t:
	print(m * k)
else:
	print(0)


(n, k) = map(int, input().split(' '))
s = input()
m = [0] * k
for i in range(0, n):
	m[ord(s[i]) - ord('A')] += 1
rez = m[0]
for i in range(1, k):
	if m[i] < rez:
		rez = m[i]
print(rez * k)


(n, l) = list(map(int, input().split()))
s = input()
min = n
for i in range(l):
	curr_c = chr(ord('A') + i)
	curr_v = s.count(curr_c)
	if curr_v < min:
		min = curr_v
print(min * l)


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
(n, k) = ei()
s = input()
letter = [chr(i) for i in range(65, 65 + k)]
x = [i for i in s]
hm = Counter(x)
c = 0
for i in letter:
	if i not in hm:
		print(0)
		c += 1
		break
if c == 0:
	ans = min(hm.values())
	print(ans * len(letter))


(n, k) = map(int, input().split())
s = input()
d = {}
for i in range(n):
	if s[i] not in d.keys():
		d[s[i]] = 1
	else:
		d[s[i]] += 1
(index, ind) = (0, n)
ma = -1
for i in range(k):
	if chr(i + 65) in d.keys():
		ind = min(ind, d[chr(i + 65)])
ma = ind * k
if len(d) < k:
	print(0)
else:
	print(ma)


(N, k) = list(map(int, input().split()))
S = input()
v = [0 for i in range(k)]
for i in S:
	v[ord(i) - 65] += 1
minl = min(v)
print(minl * k)


def main():
	(n, k) = map(int, input().split())
	s = input()
	cnt = {}
	for i in s:
		cnt[i] = cnt.get(i, 0) + 1
	ans = 10 ** 5 + 1
	for key in cnt:
		ans = min(ans, cnt[key])
	if len(cnt) < k:
		print(0)
	else:
		print(ans * k)
main()


n = input().split()
lul = list(input())
lim = int(n[1])
y = []
for i in range(lim):
	y.append(0)
for i in lul:
	x = ord(i) - 65
	y[x] += 1
y.sort()
f = y[0] * lim
print(f)


(s_length, k) = map(int, input().split())
my_dict = dict()
s = input()
for char in s:
	my_dict[char] = my_dict.get(char, 0) + 1
minimum = None
if len(my_dict) < k:
	print(0)
else:
	for value in my_dict.values():
		if minimum is None or value < minimum:
			minimum = value
	print(minimum * k)


a = input
b = int(a().split()[1])
p = input()
print(b * min((p.count(chr(65 + i)) for i in range(b))))


(n, k) = list(map(int, input().strip().split()))
s = input()
letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
L = letters[:k]
counts = {}
for x in L:
	counts[x] = s.count(x)
print(min([counts[j] for j in L]) * k)


from collections import Counter
(n, k) = map(int, input().split())
print((min(Counter(''.join(map(chr, range(ord('A'), ord('A') + k))) + input()).values()) - 1) * k)


import string
from collections import Counter
(n, k) = [int(x) for x in input().split(' ')]
counter = Counter({c: 0 for c in string.ascii_uppercase[:k]})
counter.update(input())
print(min((v for (k, v) in counter.items())) * k)


(n, k) = map(int, input().split())
nums = list(map(str, input()))
a = ord('A')
IN = True
dic = {}
chars = [chr(i) for i in range(a, a + k)]
for i in nums:
	if i not in chars:
		IN = False
for b in chars:
	if b not in nums:
		IN = False
if IN == False:
	print('0')
else:
	for l in nums:
		if l in dic:
			dic[l] += 1
		else:
			dic[l] = 1
	print(min(dic.values()) * len(dic))


class CountDict(dict):

	def __missing__(self, key):
		return 0
(n, k) = [int(i) for i in input().split(' ')]
s = input()
counts = CountDict()
for l in s:
	counts[l] += 1
longest = min(counts.values()) * k
if len(counts) < k:
	print(0)
else:
	print(longest)


(n, k) = map(int, input().split())
s = input()
m = list(set(s))
minimum = 10 ** 6
for i in range(len(m)):
	if s.count(m[i]) < minimum:
		minimum = s.count(m[i])
if len(m) == k:
	print(k * minimum)
else:
	print(0)


(n, k) = map(int, input().split())
s = input()
alph = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
mn = 10000000
for i in range(k):
	mn = min(mn, s.count(alph[i]))
print(mn * k)


from collections import Counter
(n, k) = [int(w) for w in input().split()]
s = input()
c = Counter(s)
print(k * min((c[chr(65 + i)] for i in range(k))))


(n, k) = tuple(map(int, input().split()))
s = input()
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'][:k]
count_array = []
for i in alphabet:
	count_array.append(s.count(i.upper()))
if count_array.count(0) != 0:
	print(0)
else:
	print(min(count_array) * k)


(n, k) = map(int, input().split())
s = list(input())
l = []
for i in range(k):
	l.append(chr(65 + i))
z = list(set(s))
if len(z) < k:
	print('0')
else:
	m = []
	for i in z:
		if i in l:
			m.append(s.count(i))
	print(min(m) * k)


l = [chr(i) for i in range(65, 91)]
(n, k) = map(int, input().split())
s = list(input())
z = []
for i in range(k):
	t = s.count(l[i])
	z.append(t)
a = min(z)
print(a * k)


(n, k) = map(int, input().split())
s = input()
print(k * min((s.count(c) for c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[:k])))


(n, k) = map(int, input().split())
s = input()
S = set(s)
a = 65
d = {}
if len(S) == k:
	for i in s:
		d.setdefault(i, 0)
		d[i] += 1
	mai = []
	for (q, v) in d.items():
		mai.append(v)
	mai.sort()
	print(mai[0] * k)
else:
	print(0)


import string
(n, k) = map(int, input().split())
alphabets = list(string.ascii_uppercase)
char_count = {}
for i in range(0, k):
	char_count[alphabets[i]] = 0
s = input()
for i in range(0, n):
	char_count[s[i]] += 1
min_count = n
for (_, v) in char_count.items():
	if v < min_count:
		min_count = v
print(min_count * k)


ler = input('')
ler = ler.split()
n = int(ler[0])
k = int(ler[1])
resp = [0] * k
s = input('')
for letra in s:
	resp[ord(letra) - ord('A')] += 1
print(min(resp) * k)


(n, k) = map(int, input().split())
s = input()
K = [0] * k
for i in range(n):
	K[ord(s[i]) - ord('A')] += 1
ans = min(K) * k
print(ans)


import sys
(n, k) = map(int, input().split())
s = input()
c = [0 for i in range(0, k)]
for j in s:
	i = ord(j) - ord('A')
	c[i] += 1
ans = 0
minc = 100005
for i in range(0, k):
	if c[i] == 0:
		print(0)
		sys.exit(0)
	minc = min(minc, c[i])
print(minc * k)


(t, a) = map(int, input().split())
s = input()
m = t
for i in range(a):
	m = min(s.count(chr(65 + i)), m)
print(m * a)


T_ON = 0
DEBUG_ON = 1
MOD = 998244353

def solve():
	(n, k) = read_ints()
	G = Counter(input())
	if len(G) < k:
		print(0)
	else:
		print(k * min(G.values()))

def main():
	T = read_int() if T_ON else 1
	for i in range(T):
		solve()

def debug(*xargs):
	if DEBUG_ON:
		print(*xargs)
from collections import *
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def read_int():
	return int(input())

def read_ints():
	return list(map(int, input().split()))

def print_nums(nums):
	print(' '.join(map(str, nums)))

def YES():
	print('YES')

def Yes():
	print('Yes')

def NO():
	print('NO')

def No():
	print('No')

def First():
	print('First')

def Second():
	print('Second')

def fib(n):
	(a, b) = (0, 1)
	for _ in range(n):
		(a, b) = (b, a + b)
	return a

def fib_ns(n):
	assert n >= 1
	f = [0 for _ in range(n + 1)]
	f[0] = 0
	f[1] = 1
	for i in range(2, n + 1):
		f[i] = f[i - 1] + f[i - 2]
	return f

def fib_to_n(n):
	f = []
	(a, b) = (0, 1)
	while a <= n:
		f.append(a)
		(a, b) = (b, a + b)
	return f

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def xgcd(a, b):
	(x0, x1, y0, y1) = (0, 1, 1, 0)
	while a != 0:
		((q, a), b) = (divmod(b, a), a)
		(y0, y1) = (y1, y0 - q * y1)
		(x0, x1) = (x1, x0 - q * x1)
	return (b, x0, y0)

def lcm(a, b):
	d = gcd(a, b)
	return a * b // d

def is_even(x):
	return x % 2 == 0

def is_odd(x):
	return x % 2 == 1

def modinv(a, m):
	(g, x, _) = xgcd(a, m)
	if g != 1:
		raise Exception('gcd(a, m) != 1')
	return x % m

def mod_add(x, y):
	x += y
	while x >= MOD:
		x -= MOD
	while x < 0:
		x += MOD
	return x

def mod_mul(x, y):
	return x * y % MOD

def mod_pow(x, y):
	if y == 0:
		return 1
	if y % 2:
		return mod_mul(x, mod_pow(x, y - 1))
	p = mod_pow(x, y // 2)
	return mod_mul(p, p)

def mod_inv(y):
	return mod_pow(y, MOD - 2)

def mod_div(x, y):
	return mod_mul(x, mod_inv(y))

def is_prime(n):
	if n == 1:
		return False
	for i in range(2, int(n ** 0.5) + 1):
		if n % i:
			return False
	return True

def gen_primes(n):
	P = [True for _ in range(n + 1)]
	P[0] = P[1] = False
	for i in range(int(n ** 0.5) + 1):
		if P[i]:
			for j in range(2 * i, n + 1, i):
				P[j] = False
	return P
main()


(a, b) = list(map(int, input().split()))
t = list(input())
if len(set(t)) == b:
	s = []
	u = list(set(t))
	for i in u:
		s.append(t.count(i))
	print(min(s) * b)
else:
	print(0)


(n, k) = map(int, input().split())
s = input()

def char_frequency(s):
	dict = {}
	for n in s:
		keys = dict.keys()
		if n in keys:
			dict[n] += 1
		else:
			dict[n] = 1
	return dict
d = char_frequency(s)
ans = min(d.values())
count = 0
for n in d.keys():
	count += 1
if count >= k:
	print(ans * k)
else:
	print(0)


(n, k) = map(int, input().split())
arr = list(input().strip())
d = {}
for i in arr:
	if i in d.keys():
		d[i] += 1
	else:
		d[i] = 1
if len(d) < k:
	print(0)
else:
	minn = 10 ** 100
	for i in d.keys():
		minn = min(minn, d[i])
	print(minn * k)


(n, k) = map(int, input().split())
s = list(input())
a = set()
for i in s:
	a.add(i)
b = [s.count(i) for i in a]
if len(a) != k:
	print(0)
else:
	print(min(b) * k)


(a, b) = map(int, input().split())
s = str(input())
l = list(s)
e = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
k = set(l)
if len(k) < b:
	print('0')
else:
	r = []
	for i in range(b):
		f = l.count(e[i])
		r.append(f)
	print(b * min(r))


(n, k) = map(int, input().split(' '))
s = input()
s = s.lower()
a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
l = []
for i in range(k):
	l.append(s.count(a[i]))
print(min(l) * k)


(n, k) = map(int, input().split())
counts = [0] * k
base = ord('A')
for c in input():
	counts[ord(c) - base] += 1
print(min(counts) * k)


from sys import *
(a, b) = map(int, input().split())
(s, dict, mini) = (input(), {}, 99999999)
for i in s:
	if i in dict:
		dict[i] += 1
	else:
		dict[i] = 1
for (key, values) in dict.items():
	mini = min(mini, values)
if len(dict) >= b:
	print(mini * b)
else:
	print(0)


from collections import Counter
q = int(input().split()[1])
y = input()
cnt = Counter(y)
print(0 if len(cnt) < q else cnt.most_common()[-1][1] * q)


import sys
from bisect import bisect_left, bisect_right
from collections import deque, Counter
from math import gcd, sqrt, factorial, ceil, log10
from itertools import permutations
inf = float('inf')
mod = 1000000007
mini = 1000000007

def fact(n):
	if n == 0:
		return 1
	p = 1
	d = 10 ** 9 + 7
	for i in range(1, n + 1):
		p = p * i
		p = p % d
	return p

def ncr(n, r):
	d = 10 ** 9 + 7
	num = fact(n)
	den = fact(r) * fact(n - r) % d
	den = pow(den, d - 2, d)
	return num * den % d

def sieve(n):
	prime = [True for i in range(n + 1)]
	lst = [0] * (n + 1)
	p = 2
	while p * p <= n:
		if prime[p]:
			lst[p] = p
			for i in range(p * p, n + 1, p):
				if prime[i] == True:
					prime[i] = False
					lst[i] = p
		p = p + 1
	for i in range(1, n + 1):
		if lst[i] == 0:
			lst[i] = i
	mylist = [0] * (n + 1)
	for i in range(2, n + 1):
		mylist[lst[i]] = mylist[lst[i]] + 1
	return mylist

def binary(number):
	result = 0
	while number:
		result = result + 1
		number = number & number - 1
	return result

def calculate_factors(n):
	hh = [1] * (n + 1)
	p = 2
	while p * p < n:
		if hh[p] == 1:
			for i in range(p * 2, n, p):
				hh[i] = 0
		p += 1
	total = 1
	for p in range(2, n + 1):
		if hh[p] == 1:
			count = 0
			if n % p == 0:
				while n % p == 0:
					n = int(n / p)
					count += 1
				total *= count + 1
	return total

def prime_factors(n):
	i = 2
	factors = set()
	while i * i <= n:
		if n % i:
			i += 1
		else:
			factors.add(n // i)
			n = n // i
			factors.add(i)
	if n > 1:
		factors.add(n)
	return factors

def isPrime(n):
	if n == 2 or n == 3:
		return True
	if n % 2 == 0 or n < 2:
		return False
	for i in range(3, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, k) = get_ints()
string = input()
mydict = dict()
for i in range(65, 92):
	mydict[chr(i)] = 0
for i in string:
	mydict[i] = mydict.get(i, 0) + 1
mini = 1000000000
for i in range(65, 65 + k):
	if mydict[chr(i)] < mini:
		mini = mydict[chr(i)]
print(mini * k)


(n, k) = map(int, input().split())
s = input()
t = n
p = list(set(s))
for i in p:
	t = min(t, s.count(i))
if k == len(p):
	print(k * t)
else:
	print('0')


(n, k) = map(int, input().split())
string = input()
dictionary = {}
for i in range(len(string)):
	if string[i] in dictionary:
		dictionary[string[i]] += 1
	else:
		dictionary[string[i]] = 1
minimum = dictionary[string[0]]
if len(dictionary) == k:
	for i in dictionary.keys():
		if dictionary[i] < minimum:
			minimum = dictionary[i]
	print(minimum * k)
else:
	print('0')


from string import ascii_uppercase
(n, k) = list(map(int, input().split()))
text = input()
strok = ascii_uppercase[:k]
rez = 0
kol = text.count(strok[0])
for x in strok[1:]:
	kol = min(kol, text.count(x))
rez = kol * len(strok)
print(rez)


(n, k) = map(int, input().split())
s = input()
t = set(s)
c = 0
if k <= len(t):
	c = len(s)
	for i in t:
		c = min(c, s.count(i))
print(c * k)


import string
(n, k) = map(int, input().split())
s = input()
min = s.count('A')
for i in string.ascii_uppercase[1:k]:
	if s.count(i) < min:
		min = s.count(i)
print(min * k)


import string
s = input().split()
n = int(s[0])
k = int(s[1])
s = input()
min_occ = n
found_all = True
for i in range(k):
	cnt = s.count(string.ascii_uppercase[i])
	if cnt == 0:
		found_all = False
		break
	if cnt < min_occ:
		min_occ = cnt
if not found_all:
	print(0)
else:
	print(k * min_occ)


al = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
(x, y) = map(int, input().split())
a = input()
print(min([a.count(al[i]) for i in range(y)]) * y)


(n, k) = map(int, input().split())
mot = input()
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
s = alphabet[:k]
l = []
for elem in s:
	occ = mot.count(elem)
	l.append(occ)
l.sort()
print(l[0] * k)


def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
from collections import Counter
alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
(n, k) = mi()
s = input().strip()
c = Counter(s)
mn = 10 ** 9
for ch in alpha[:k]:
	mn = min(mn, c[ch])
print(mn * k)


z = list(map(int, input().split()))
x = list(input().lower())
k = ''
d = []
for i in range(z[1]):
	k += chr(i + 97)
for i in k:
	d.append(x.count(i))
print(min(d) * z[1])


def longestSubsequence(s, k):
	count = [0] * k
	for letter in s:
		if ord(letter) < ord('A') + k:
			count[ord(letter) - ord('A')] += 1
	return min(count) * k
(n, k) = map(int, input().split())
s = input()
print(longestSubsequence(s, k))


(n, k) = tuple([int(i) for i in input().split()])
letters = {}
for letter in input():
	letters[letter] = letters.get(letter, 0) + 1
if len(letters.keys()) == k:
	print(min(letters.values()) * k)
else:
	print(0)


(a, b) = map(int, input().split())
string = input()
alphabets = [chr(t) for t in range(65, 65 + b)]
dictionary = {t: string.count(t) for t in alphabets}
print(min(dictionary.values()) * len(alphabets))


(n, k) = map(int, input().split())
maps = {}
S = input()
m = 0
for s in S:
	if s not in maps:
		maps[s] = 1
	else:
		maps[s] += 1
for s in maps:
	if m == 0:
		m = maps[s]
	else:
		m = min(m, maps[s])
if len(maps) == k:
	print(m * len(maps))
else:
	print(0)


(n, k) = input().split(' ')
n = int(n)
k = int(k)
s = input()
a = []
for i in range(0, k):
	c = chr(65 + i)
	a.append(s.count(c))
a = sorted(a)
print(a[0] * k)


d = {}
(n, k) = map(int, input().split())
for i in range(65, 65 + k):
	d[chr(i)] = 0
s = input()
for i in s:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
l = []
for i in d:
	l.append(d[i])
print(min(l) * len(d))


(n, k) = input().split()
(n, k) = (int(n), int(k))
st = str(input())
x = [0 for i in range(1, k + 1)]
for g in range(0 + 65, k + 65):
	x[g - 65] = st.count(chr(g))
print(min(x) * k)


s = input().split(' ')
num = int(s[1])
st = input()
ls = []
for i in st:
	if i not in ls:
		ls.append(i)
len_str = len(ls)
sl = [0] * len_str
for (j, k) in enumerate(ls):
	for i in st:
		if k == i:
			sl[j] = sl[j] + 1
if len_str < num:
	print(0)
else:
	mini = min(sl)
	print(mini * len(sl))


from collections import Counter
from string import ascii_uppercase
(n, k) = [int(i) for i in input().split()]
s = input()
c = Counter(s)
print(min([c[i] for i in ascii_uppercase[:k]]) * k)


(n, k) = map(int, input().split())
s = input()
q = [0] * 26
for i in range(n):
	q[ord(s[i]) - 65] += 1
f = 0
mini = 7778676877867
for i in range(k):
	if mini > q[i]:
		mini = q[i]
	if q[i] == 0:
		f = 1
		break
if f == 1:
	print('0')
else:
	print(mini * k)


def rahul(word):
	return [char for char in word]
a = [int(a) for a in input().split()]
b = rahul(input())
r = 0
c = list()
while r < a[1]:
	s = b.count(chr(ord('A') + r))
	c.append(s)
	r = r + 1
print(min(c) * a[1])


(n, k) = map(int, input().split())
my_list = [0] * k
a = input()
for c in a:
	my_list[ord(c) - 65] += 1
print(min(my_list) * k)


(n, k) = map(int, input().split())
d = dict()
for c in input():
	if c in d:
		d[c] += 1
	else:
		d[c] = 1
if len(d) < k:
	print(0)
	exit()
print(k * min(d.values()))


I = lambda : map(int, input().split())
(n, k) = I()
s = input()
cm = n
for i in range(k):
	cm = min(cm, s.count(chr(i + 65)))
	if cm == 0:
		exit(print(0))
print(cm * k)


s1 = input()
s1 = [int(i) for i in s1.split()]
n = s1[0]
k = s1[1]
s = input()
alph = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
firstAlph = alph[:k]
lits = []
for i in firstAlph:
	lits.append(s.count(i))
print(k * min(lits))


(n, k) = map(int, input().split())
s = input()
a = [0 for i in range(0, 91)]
dem = 0
for i in s:
	x = int(ord(i))
	a[x] += 1
min = 0
for i in range(65, 91):
	if a[i] > 0:
		dem += 1
		if dem == 1:
			min = a[i]
		elif a[i] < min:
			min = a[i]
if dem == k:
	print(min * k)
else:
	print(0)


from collections import Counter, defaultdict, deque
get = lambda : int(input())
read = lambda : list(map(int, input().split()))
mod = 10 ** 9 + 7
inf = float('inf')

def solve(s, m):
	d = Counter(s)
	if len(d) < m:
		return 0
	return min(d.values()) * m
while True:
	try:
		(n, m) = read()
		s = input()
		print(solve(s, m))
	except:
		break


read = lambda : map(int, input().split())
(n, k) = read()
s = input()
c = [0] * 26
for i in range(n):
	if s[i] <= chr(ord('A') + k - 1):
		c[ord(s[i]) - ord('A')] += 1
print(min(c[:k]) * k)


(n, k) = map(int, input().split())
s = input()
x = {}
lis = [chr(65 + x) for x in range(k)]
for i in lis:
	if i not in s:
		print(0)
		exit()
for i in s:
	if i not in x:
		x[i] = 1
	else:
		x[i] += 1
res = list(x.values())
print(min(res) * k)


(s, n) = map(int, input().split())
string = str(input())
x = []
t = 65
for i in range(n):
	x.append(chr(t))
	t = t + 1
ans = 0
minimum = len(string)
for i in x:
	temp = string.count(i)
	if temp < minimum:
		minimum = temp
print(minimum * n)


from string import ascii_uppercase
from collections import Counter
(n, k) = input().split()
(n, k) = (int(n), int(k))
s = list(input().strip())
a = Counter(s)
letters = list(ascii_uppercase[:k])
menor = -1
for i in letters:
	if i not in a.keys():
		print(0)
		exit()
	elif menor == -1 or menor > a[i]:
		menor = a[i]
print(menor * k)


(l, sub) = map(int, input().split())
s = input()
mini = 100001
se = set(s)
if len(se) < sub:
	print(0)
else:
	for i in se:
		if i in s:
			mini = min(mini, s.count(i))
	print(mini * len(se))


from collections import defaultdict
inp = input()
inp_arr = inp.split()
n = int(inp_arr[0])
k = int(inp_arr[1])
s = input()
freq = defaultdict(int)
for ch in s:
	freq[ch] += 1
min_freq = min(freq.values())
result = 0
if len(freq) == k:
	result = len(freq) * min_freq
print(result)


(n, k) = map(int, input().split())
s = input()
l = []
if len(set(s)) < k:
	print(0)
else:
	for i in set(s):
		l.append(s.count(i))
	print(min(l) * len(set(s)))


a = input().split()
n = int(a[0])
k = int(a[1])
s = input()
freq = [0] * k
for i in range(n):
	freq[ord(s[i]) - 65] += 1
minimo = min(freq)
tam = n
for i in range(k):
	if freq[i] > minimo:
		tam -= freq[i] - minimo
		freq[i] = minimo
print(tam)


(n, k) = map(int, input().split())
s = input()
alph = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
a = list(set(s))
a.sort()
if a != list(alph[:k]):
	print(0)
else:
	b = [0] * k
	for i in range(n):
		b[alph.find(s[i])] += 1
	print(k * min(b))


import string
n = list(map(int, input().split()))
k = n[1]
st = str(input())
ele = n[0]
c = 0
for i in string.ascii_uppercase:
	c += 1
	if c > k:
		break
	elif st.count(i) < ele:
		ele = st.count(i)
print(k * ele)


try:
	(n, k) = map(int, input().split())
	s = input()
	l = list(s)
	s1 = set(l)
	l1 = list(s1)
	l2 = []
	for i in l1:
		l2.append(l.count(i))
	if k <= len(l1):
		print(min(l2) * k)
	else:
		print('0')
except EOFError:
	pass


(n, k) = map(int, input().split(' '))
string = input()
s = set(string)
b = []
if len(s) == k:
	for i in s:
		a = string.count(i)
		b.append(a)
	c = min(b)
	d = c * k
	print(d)
elif len(s) != k:
	print(0)


import sys, os, io
(n, k) = [int(i) for i in input().split()]
s = input()
cnt = [0] * k
for i in s:
	cnt[ord(i) - 65] += 1
print(min(cnt) * k)


(n, k) = [int(num) for num in input().split()]
str = input()
min = n
for i in range(k):
	if str.count(chr(65 + i)) < min:
		min = str.count(chr(65 + i))
print(min * k)


inp = input().split()
n = int(inp[0])
k = int(inp[1])
s = input()
cnt = {}
for c in s:
	cnt[c] = cnt.get(c, 0) + 1
if len(cnt) < k:
	print(0)
else:
	ans = cnt['A']
	for (c, v) in cnt.items():
		ans = min(ans, v)
	print(ans * k)


(n, k) = [int(x) for x in input().split()]
s = input()
freq = []
for i in range(0, k):
	freq.append(0)
for i in range(0, n):
	freq[ord(s[i]) - 65] += 1
min_freq = freq[0]
for i in range(1, k):
	if freq[i] < min_freq:
		min_freq = freq[i]
print(min_freq * k)


(a, b) = [int(i) for i in input().split()]
l = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
s = str(input())
min = 10 ** 9
for i in range(0, b):
	f = s.count(l[i])
	if f < min:
		min = f
print(min * b)