Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.

There are $n$ stages available. The rocket must contain exactly $k$ of them. Stages in the rocket should be ordered by their weight. So, after the stage with some letter can go only stage with a letter, which is at least two positions after in the alphabet (skipping one letter in between, or even more). For example, after letter 'c' can't go letters 'a', 'b', 'c' and 'd', but can go letters 'e', 'f', ..., 'z'.

For the rocket to fly as far as possible, its weight should be minimal. The weight of the rocket is equal to the sum of the weights of its stages. The weight of the stage is the number of its letter in the alphabet. For example, the stage 'a 'weighs one ton,' b 'weighs two tons, and' z' — $26$ tons.

Build the rocket with the minimal weight or determine, that it is impossible to build a rocket at all. Each stage can be used at most once.


-----Input-----

The first line of input contains two integers — $n$ and $k$ ($1 \le k \le n \le 50$) – the number of available stages and the number of stages to use in the rocket.

The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build the rocket. Each stage can be used at most once.


-----Output-----

Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all.


-----Examples-----
Input
5 3
xyabd

Output
29
Input
7 4
problem

Output
34
Input
2 2
ab

Output
-1
Input
12 1
abaabbaaabbb

Output
1


-----Note-----

In the first example, the following rockets satisfy the condition:



 "adx" (weight is $1+4+24=29$);

 "ady" (weight is $1+4+25=30$);

 "bdx" (weight is $2+4+24=30$);

 "bdy" (weight is $2+4+25=31$).

Rocket "adx" has the minimal weight, so the answer is $29$.

In the second example, target rocket is "belo". Its weight is $2+5+12+15=34$.

In the third example, $n=k=2$, so the rocket must have both stages: 'a' and 'b'. This rocket doesn't satisfy the condition, because these letters are adjacent in the alphabet. Answer is -1.

Source: codeforces | Difficulty: EASY
Tags: Sorting

Implementation

Greedy algorithms


Solutions:
(n, k) = map(int, input().split())
s = input()
c = [0] * 26
for i in s:
	c[ord(i) - 97] += 1
ans = 0
p = 0
while p < 26 and k > 0:
	if c[p] != 0:
		ans += p + 1
		p += 2
		k -= 1
	else:
		p += 1
if k > 0:
	print(-1)
else:
	print(ans)


I = lambda : map(int, input().split())
(n, k) = I()
a = sorted(input())
p = [a[0]]
b = ord(a[0])
y = b - ord('a')
for i in range(1, n):
	if len(p) == k:
		break
	if ord(a[i]) - b >= 2:
		y += ord(a[i]) - ord('a')
		b = ord(a[i])
		p.append(a[i])
if len(p) < k:
	print(-1)
else:
	print(y + k)


(n, k) = map(int, input().split())
w = p = 0
for c in map(ord, sorted(input())):
	if c - p > 1:
		w += c - 96
		p = c
		k -= 1
	if k == 0:
		break
print([w, -1][k > 0])


(n, k) = map(int, input().split())
a = list(input())
j = 0
a = list(set(a))
a.sort()
ans = []
for i in range(len(a)):
	if j >= k:
		break
	if ord(a[i]) - 97 not in ans and ord(a[i]) - 95 not in ans:
		ans.append(ord(a[i]) - 96)
		j += 1
if j < k:
	print(-1)
else:
	print(sum(ans))


(n, k) = map(int, input().split(' '))
s = input()
s = sorted(s)
a = []
for i in range(n):
	a.append(ord(s[i]) - 96)
c = 1
ans = a[0]
h = a[0]
for i in range(1, n):
	if c < k:
		if a[i] - 1 > h:
			ans += a[i]
			c += 1
			h = a[i]
if c == k:
	print(ans)
else:
	print(-1)


f = -1000000000
q = 0

def ves(f, q, i, y):
	e = f
	w = ord(a[i]) - 96
	if w - e != 1 and w - e != 0:
		y += 1
		q = q + ord(a[i]) - 96
		f = w
	return (f, q, y)
y = 0
a = input()
(n, k) = a.split()
n = int(n)
k = int(k)
a = list(input())
a.sort()
for i in range(n):
	(f, q, y) = ves(f, q, i, y)
	if y == k:
		break
if y == k:
	print(q)
else:
	print(-1)


(n, k) = map(int, input().split())
stages = sorted(input().strip())
i = 0
total = 0
last = -1
while k > 0 and i < n:
	wi = ord(stages[i]) - ord('a') + 1
	if wi > last + 1:
		total += wi
		k -= 1
		last = wi
	i += 1
if k > 0:
	print(-1)
else:
	print(total)


(n, m) = [int(e) for e in input().split(' ')]
line = list(input())
line.sort()
alph = 'abcdefghijklmnopqrstuvwxyz'
ans = alph.index(line[0]) + 1
temp = line[0]
m -= 1
for k in range(1, n):
	if not m:
		break
	if alph.index(line[k]) > alph.index(temp) + 1:
		ans += alph.index(line[k]) + 1
		temp = line[k]
		m -= 1
if m:
	print(-1)
else:
	print(ans)


(n, k) = [int(x) for x in input().split()]
s = input()
ws = set()
for c in s:
	ws.add(ord(c) - ord('a') + 1)
aws = list(ws)
aws.sort()
size = 0
cost = 0
last = None
i = 0
while i < len(aws):
	cur = aws[i]
	if last is None or cur - last >= 2:
		last = cur
		cost += cur
		size += 1
		if size >= k:
			break
	i += 1
if size >= k:
	print(cost)
else:
	print(-1)


(n, k) = map(int, input().split())
c = 'abcdefghijklmnopqrstuvwxyz'
s = input()
a = list(s)
a.sort()
abcd = 1
b = a[0]
d = c.index(b[-1]) + 1
for i in range(1, k):
	for j in range(abcd, len(a)):
		g = c.index(a[j])
		h = c.index(b[-1])
		if g - h >= 2:
			d = d + c.index(a[j]) + 1
			abcd = j + 1
			b = b + a[j]
			break
if len(b) == k:
	print(d)
else:
	print(-1)


p = list(map(int, input().split()))
n = p[0]
k = p[1]
s = input().strip()
s = list(s)
s.sort()
s2 = s
i = 0
sums = ord(s2[0])
sums = sums - 96
count = 1
while count < k and i < len(s2):
	flag = 0
	for j in range(i + 1, len(s2)):
		if abs(ord(s2[j]) - ord(s2[i])) >= 2 and count < k:
			sums += ord(s2[j])
			sums = sums - 96
			i = j
			count += 1
			flag = 1
			break
		else:
			continue
	if flag == 0:
		i += 1
if count < k:
	sums = -1
if len(s) != n:
	sums = -1
print(sums)


(n, k) = map(int, input().split())
s = input()
a = []
for i in s:
	a.append(ord(i) - ord('a') + 1)
a.sort()
ans = 0
tmp = -1
for i in a:
	if tmp == -1 or i >= tmp:
		ans += i
		tmp = i + 2
		k -= 1
		if k == 0:
			break
if k == 0:
	print(ans)
else:
	print(-1)


def solve():
	(n, k) = map(int, input().split())
	s = sorted(input())
	s_ans = s[0]
	ans = ord(s[0]) - ord('a') + 1
	for i in range(1, n):
		if len(s_ans) >= k:
			break
		if ord(s[i]) - ord(s_ans[-1]) >= 2:
			s_ans += s[i]
			ans += ord(s[i]) - ord('a') + 1
	if len(s_ans) < k:
		print(-1)
		return
	print(ans)
solve()


(n, k) = map(int, input().split())
s = list(input())
d = {chr(i + 96): i for i in range(1, 27)}
s.sort()
s1 = [s[0]]
k -= 1
res = d[s[0]]
if k != 0:
	if len(s) > 1:
		i = 1
		while i != len(s) - 1:
			if ord(s[i]) - ord(s1[-1]) > 1:
				res += d[s[i]]
				s1.append(s[i])
				k -= 1
				if k == 0:
					break
			i += 1
	if k == 1:
		if ord(s[i]) - ord(s1[-1]) > 1:
			res += d[s[-1]]
			k -= 1
print(res if k == 0 else -1)


(n, k) = (int(i) for i in input().split())
l = sorted(list(input()))
c = 1
c1 = l[0]
w = ord(l[0]) - 96
if k == 1:
	print(w)
else:
	for i in range(1, n):
		if c == k:
			break
		elif ord(l[i]) - ord(c1) >= 2:
			w += ord(l[i]) - 96
			c1 = l[i]
			c += 1
	if c < k:
		print(-1)
	else:
		print(w)


(n, k) = list(map(int, input().split()))
po = list(input())
po.sort()
l = []
tom = list(range(1, 27))
sa = list('abcdefghijklmnopqrstuvwxyz')
l.append(tom[sa.index(po[0])])
x = 1
for item in po[x:]:
	if sa.index(po[po.index(item)]) - sa.index(sa[tom.index(l[-1])]) > 1:
		l.append(tom[sa.index(po[po.index(item)])])
	else:
		pass
if len(l) == k:
	print(sum(l))
elif len(l) > k:
	print(sum(l[0:k]))
else:
	print('-1')


def scanf(obj=list, type=int, sep=' '):
	return obj(map(type, input().split(sep)))
(n, m) = scanf()
s = input()
s = list(map(ord, s))
s.sort()
(ans, p) = (0, 0)
for i in range(n):
	if not m:
		break
	if s[i] - p > 1:
		ans += s[i] - ord('a') + 1
		m -= 1
		p = s[i]
if not m:
	print(ans)
else:
	print(-1)


def Plus3(Sum, A, B):
	return Sum + (ord(A) - 96) + (ord(B) - 96)

def Plus2(Sum, A):
	return Sum + (ord(A) - 96)
(n, k) = map(int, input().split())
String = input()
String = list(String)
if k > n:
	print('-1')
else:
	String.sort()
	Sum = ord(String[0]) - 96
	LIndx = 0
	Ki = 1
	flag = False
	flagskip = False
	for j in range(0, n):
		if Ki == k:
			break
		if ord(String[LIndx]) - ord(String[j]) != -1 and ord(String[LIndx]) - ord(String[j]) != 0:
			Sum = Plus2(Sum, String[j])
			LIndx = j
			Ki += 1
	if Ki == k:
		print(Sum)
	else:
		print('-1')


(n, k) = list(map(int, input().split()))
s = sorted(list(set(input().strip())))
(a, g, p) = (0, 0, 0)
for c in s:
	xx = ord(c)
	if xx >= p + 2:
		(a, g, p) = (a + xx - 96, g + 1, xx)
	if g == k:
		break
print(-1 if g < k else a)


(n, k) = list(map(int, input().split()))
s = input()
t = [0] * 26
for i in s:
	t[ord(i) - 97] += 1
i = 0
ret = 0
d = 0
while i < 26:
	if d == k:
		break
	if t[i] > 0:
		ret += i + 1
		d += 1
		i += 1
	i += 1
if d < k:
	print(-1)
else:
	print(ret)


(n, k) = [int(x) for x in input().split()]
MAXV = 999999999999999999999
s = input()
s = list(set(s))
n = len(s)
s.sort()
res = MAXV
cur = 0
st = 0
fin = st + 1
cur = ord(s[st]) - ord('a') + 1
taken = [s[st]]
while len(taken) < k and fin < n:
	if ord(s[fin]) - ord(taken[-1]) > 1:
		cur += ord(s[fin]) - ord('a') + 1
		taken.append(s[fin])
	fin += 1
if len(taken) == k:
	print(cur)
else:
	print(-1)


(n, k) = map(int, input().split())
s = input()
s = sorted(s)
ans = 0
pre = 0
for i in range(n):
	if k == 0:
		break
	if ord(s[i]) >= 2 + pre:
		k -= 1
		ans += ord(s[i]) - 97 + 1
		pre = ord(s[i])
if k == 0:
	print(ans)
else:
	print(-1)


(anz_stages, anz_stages_in_rocket) = input().strip().split()
available_stages = list(input().strip())
available_stages = list(map(lambda x: ord(x) - 96, available_stages))
available_stages.sort()
answer_list = []
answer_list.append(available_stages[0])
i = 0
while len(answer_list) < int(anz_stages_in_rocket):
	i += 1
	if len(available_stages) <= i:
		print(-1)
		break
	if available_stages[i] - answer_list[-1] <= 1:
		continue
	else:
		answer_list.append(available_stages[i])
else:
	print(sum(answer_list))


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

def cost(c):
	return ord(c) - ord('a') + 1
total = cost(s[0])
k -= 1
curr = 0
i = 1
while i < n:
	if k == 0:
		break
	if cost(s[i]) - cost(s[curr]) >= 2:
		total += cost(s[i])
		curr = i
		k -= 1
	i += 1
if k > 0:
	print(-1)
else:
	print(total)


(a, b) = map(int, input().split())
p = input()
c = sorted(p)
k = ord(c[0]) - ord('a') + 1
b -= 1
j = 0
l = 0
for i in range(1, len(c)):
	if ord(c[i]) - ord('a') - (ord(c[j]) - ord('a')) > 1 and b > 0:
		k += ord(c[i]) - ord('a') + 1
		j = i
		b -= 1
if b == 0:
	print(k)
else:
	print(-1)


(n, k) = map(int, input().split())
s = list(input())
s.sort()
i = 0
j = 1
t = 0
z = []
while t < k and i < len(s) and (j < len(s)):
	if abs(ord(s[i]) - ord(s[j])) >= 2:
		z.append(s[i])
		z.append(s[j])
		i = j
		j += 1
	else:
		j += 1
z = list(set(z))
z.sort()
if k == 1:
	print(ord(s[0]) - 96)
elif len(z) < k:
	print(-1)
else:
	for i in range(k):
		t += ord(z[i]) - 96
	print(t)


(x, y) = map(int, input().split())
t = list(input())
t.sort()
r = t[0]
i = 1
s = ord(t[0]) - 96
while len(r) != y:
	if i >= x:
		break
	if ord(t[i]) - ord(r[-1]) <= 1:
		pass
	else:
		r = r + t[i]
		s = s + ord(t[i]) - 96
	i = i + 1
if len(r) < y:
	print(-1)
else:
	print(s)


(n, k) = list(input().split())
(n, k) = [int(n), int(k)]
s = input().strip()
sl = list(s)
temp_k = k
temp_string = []
sl = sorted(sl)
result = 0
for i in range(len(sl)):
	if temp_k == 0:
		break
	if i == 0:
		result += ord(sl[i])
		temp_k -= 1
		temp_string.append(sl[i])
	elif ord(sl[i]) - ord(temp_string[-1]) >= 2:
		result += ord(sl[i])
		temp_k -= 1
		temp_string.append(sl[i])
if temp_k == 0:
	print(str(result - k * 96))
else:
	print('-1')


(n, k) = map(int, input().strip().split(' '))
s = sorted(input())
weight_map = dict(zip('abcdefghijklmnopqrstuvwxyz', range(1, 27)))
out = []
weight = weight_map[s[0]]
tmp = s[0]
count = 1
i = 1
while i < n:
	if count == k:
		break
	if s[i] != tmp and weight_map[s[i]] - weight_map[tmp] != 1:
		weight += weight_map[s[i]]
		tmp = s[i]
		count += 1
	i += 1
if count == k:
	print(weight)
else:
	print(-1)


(n, k) = list(map(int, input().split()))
s = input()
a = [0] * 26
for i in range(n):
	a[ord(s[i]) - 97] = 1
uk = 0
su = 0
while 1:
	if a[uk] == 1:
		su += uk + 1
		uk += 2
		k -= 1
	else:
		uk += 1
	if uk >= 26 or k == 0:
		break
if k == 0:
	print(su)
else:
	print(-1)


def main():
	(n, k) = [int(x) for x in input().split()]
	s = input()
	s = ''.join(sorted(s))
	count = 0
	last = None
	ans = 0
	for (i, c) in enumerate(s):
		if i == 0:
			last = c
			count += 1
			ans += ord(c) - 96
			if count == k:
				break
			continue
		if ord(c) - ord(last) < 2:
			continue
		last = c
		count += 1
		ans += ord(c) - 96
		if count == k:
			break
	else:
		print(-1)
		return
	print(ans)
main()


(n, k) = map(int, input().split())
a = list(map(ord, list(input())))
a.sort()
sum = a[0] - ord('a') + 1
c = a[0]
(count, i) = (1, 1)
while i < n and count < k:
	if a[i] <= c + 1:
		i += 1
		continue
	c = a[i]
	sum += a[i] - ord('a') + 1
	count += 1
	i += 1
if count < k:
	print(-1)
else:
	print(sum)


(n, k) = map(int, input().split())
s = input()
l = []
for i in s:
	l.append(ord(i) - 96)
l = sorted(l)

def removal(l):
	for i in range(len(l)):
		if l[i + 1] - l[i] <= 1:
			l.remove(l[i + 1])
			removal(l)
try:
	removal(l)
except:
	pass
sums = 0
if len(l) >= k:
	for i in range(k):
		sums += l[i]
	print(sums)
else:
	print(-1)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
(n, k) = get_list()
s = sorted(get_string())
i = 0
flag = True
res = ''
while k > 0 and i < n:
	if i == 0:
		res += s[i]
		k -= 1
	if ord(res[-1]) + 1 < ord(s[i]):
		res += s[i]
		k -= 1
	if k > 0 and i == n - 1:
		flag = False
		break
	i += 1
if flag:
	count = 0
	for i in res:
		count += ord(i) - 96
	print(count)
else:
	print(-1)


(n, k) = map(int, input().split())
a = sorted([ord(i) - ord('a') + 1 for i in input()])
w = 0
while k > 0:
	if len(a) == 0:
		w = -1
		break
	w += a[0]
	s = 1
	while s < len(a) and a[s] <= a[0] + 1:
		s += 1
	a = a[s:]
	k -= 1
print(w)


(n, k) = map(int, input().split())
s = input()
s = sorted(s)
ans = 0
value = 0
for i in s:
	if ord(i) > value + 1:
		ans += ord(i) - 97 + 1
		k -= 1
		value = ord(i)
	if k == 0:
		break
if k > 0:
	print(-1)
else:
	print(ans)


(n, k) = input().strip().split(' ')
(n, k) = (int(n), int(k))
s = input()
arr = []
for i in s:
	arr.append(i)
arr.sort()
wt = 0
prev = -2
for i in arr:
	if prev + 2 <= ord(i) - 96:
		wt += ord(i) - 96
		prev = ord(i) - 96
		k -= 1
	if not k:
		break
if k:
	print(-1)
else:
	print(wt)


dic = {'a': '1', 'b': '2', 'c': '3', 'd': '4', 'e': '5', 'f': '6', 'g': '7', 'h': '8', 'i': '9', 'j': '10', 'k': '11', 'l': '12', 'm': '13', 'n': '14', 'o': '15', 'p': '16', 'q': '17', 'r': '18', 's': '19', 't': '20', 'u': '21', 'v': '22', 'w': '23', 'x': '24', 'y': '25', 'z': '26'}

def quick_sort(array):
	left = []
	equal = []
	greater = []
	if len(array) > 1:
		pivot = int(dic[array[0]])
		for x in array:
			if int(dic[x]) < pivot:
				left.append(x)
			elif int(dic[x]) == pivot:
				equal.append(x)
			elif int(dic[x]) > pivot:
				greater.append(x)
		return quick_sort(left) + equal + quick_sort(greater)
	else:
		return array

def stages():
	sizes = list(map(int, input().split()))
	word = input()
	word = [word[i] for i in range(len(word))]
	word = quick_sort(word)
	if sizes[1] == 0:
		return -1
	elif sizes[1] == 1:
		return int(dic[word[0]])
	elif sizes[1] > len(word):
		return -1
	else:
		total = 1
		i = 1
		saved = word[0]
		output = int(dic[word[0]])
		while True:
			if word[i] == saved or int(dic[word[i]]) - 1 == int(dic[saved]):
				i += 1
				if i >= len(word):
					return -1
			else:
				output += int(dic[word[i]])
				saved = word[i]
				total += 1
				if total == sizes[1]:
					return output
				i += 1
				if i >= len(word):
					return -1
answer = stages()
print(answer)


(n, k) = map(int, input().split())
s = input()
li = list((i for i in s))
li.sort()
alphabets = ['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']
ans = li[0]
ind = alphabets.index(ans)
if n > 1:
	for i in range(1, n):
		ind1 = alphabets.index(li[i])
		if ind1 - ind >= 2:
			ans += li[i]
			ind = ind1
		else:
			pass
if len(ans) >= k:
	sum = 0
	for i in ans[0:k]:
		sum += alphabets.index(i) + 1
	print(sum)
else:
	print(-1)


def get_order(x):
	return ord(x) - ord('a') + 1
(n, k) = list(map(int, input().split()))
s = input()
s = list(s)
s = sorted(s)
counts = 1
idx = 1
prev = s[0]
total = get_order(s[0])
while idx < len(s) and counts < k:
	if ord(s[idx]) - ord(prev) >= 2:
		prev = s[idx]
		counts += 1
		total += get_order(s[idx])
	idx += 1
if counts < k:
	print(-1)
else:
	print(total)


(n, k) = list(map(int, input().split()))
s = list(input())
s = list(sorted(s))
prv = 'Y'
cnt = 0
ans = 0
for c in s:
	if ord(prv) + 1 < ord(c):
		ans += ord(c) - ord('a') + 1
		prv = c
		cnt += 1
	if cnt == k:
		break
if cnt == k:
	print(ans)
else:
	print(-1)


n = input().split(' ')
p = input()
l = []
final = []
for i in range(len(p)):
	l.append(ord(p[i]) - 96)
l.sort()
t = l[0]
x = [t]
z = 1
for k in range(1, len(l)):
	if z >= int(n[1]):
		break
	if l[k] > max(x) + 1:
		t += l[k]
		x.append(l[k])
		z += 1
if z < int(n[1]):
	t = -1
print(t)


(n, k) = map(int, input().split())
s = list(input())
s.sort()
l = [s[0]]
w = ord(s[0]) - 96
i = 1
j = len(l)
while j < k and i < n:
	if ord(s[i]) - ord(l[j - 1]) > 1:
		l.append(s[i])
		j += 1
		w += ord(s[i]) - 96
	i += 1
if len(l) == k:
	print(w)
else:
	print(-1)


def weight(ch):
	return ord(ch) - ord('a') + 1
(n, k) = map(int, input().split())
s = input()
myList = list(s)
myList.sort()
i = 0
ves = 0
pred = -1
kol = 0
while i < len(myList) and kol < k:
	w = weight(myList[i])
	if w >= pred + 2:
		ves += w
		kol += 1
		pred = w
	i += 1
if kol == k:
	print(ves)
else:
	print(-1)


(n, k) = map(int, input().split())
s = sorted(input())
w = 0
p = '_'
for i in range(n):
	if ord(s[i]) - ord(p) > 1:
		p = s[i]
		w += ord(s[i]) - 96
		k -= 1
		if k == 0:
			print(w)
			break
else:
	print(-1)


def read():
	return int(input())

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

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

def ctoi(c):
	return ord(c) - 96
(n, k) = readmap()
S = input()
stage = [0] * 27
for s in S:
	stage[ctoi(s)] = 1
ans = 0
i = 1
while k > 0 and i < 27:
	if stage[i]:
		ans += i
		k -= 1
		i += 2
	else:
		i += 1
if k > 0:
	print(-1)
else:
	print(ans)


(n, k) = map(int, input().split())
s = sorted(input())
t = ''
p = ' '
for c in s:
	if ord(c) > ord(p) + 1:
		t += c
		p = c
ans = -1
if len(t) >= k:
	ans = sum(map(lambda x: ord(x) - 96, t[:k]))
print(ans)


(n, k) = map(int, input().split())
s = input()
count = res = 0
prev = None
for c in sorted(set(s)):
	if not res:
		res += ord(c) - ord('a') + 1
		count += 1
		prev = c
	elif prev and ord(c) - ord(prev) > 1:
		res += ord(c) - ord('a') + 1
		count += 1
		prev = c
	if count == k:
		break
print(res if count == k else -1)


from math import *
from collections import *
from operator import itemgetter
import bisect
ii = lambda : int(input())
iia = lambda : list(map(int, input().split()))
isa = lambda : list(input().split())
I = lambda : list(map(int, input().split()))
chrIdx = lambda x: ord(x) - 96
idxChr = lambda x: chr(96 + x)
(n, k) = iia()
s = input()
s = sorted(s)
x = 1
flag = -1
prev = s[0]
val = chrIdx(s[0])
if k == 1:
	flag = val
for i in range(1, n):
	if chrIdx(s[i]) - chrIdx(prev) > 1 and x < k:
		x += 1
		prev = s[i]
		val += chrIdx(s[i])
		if x >= k:
			flag = val
			break
print(flag)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
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 list(map(int, 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()
	a = sorted([ord(c) - ord('a') + 1 for c in S()])
	r = [a[0]]
	for c in a[1:]:
		if c - r[-1] > 1:
			r.append(c)
	if len(r) < k:
		return -1
	return sum(r[:k])
print(main())


(n, k) = [int(x) for x in input().strip().split(' ', 1)]
s = sorted(input())
tk = 1
w = ord(s[0]) - 96
p = ord(s[0])
if tk < k:
	for i in range(1, len(s)):
		if ord(s[i]) - p > 1:
			tk += 1
			w += ord(s[i]) - 96
			p = ord(s[i])
			if tk == k:
				break
if tk == k:
	print(w)
else:
	print('-1')


(n, k) = map(int, input().split())
s = input().rstrip()
l = list(s)
sum1 = 0
d = {}
for i in range(26):
	d[chr(97 + i)] = i + 1
l.sort()
sum1 += d[l[0]]
count = 1
(i, j) = (1, 0)
while i < len(l) and j < i and (count < k):
	if d[l[i]] < d[l[j]] + 2:
		i += 1
		continue
	else:
		sum1 += d[l[i]]
		count += 1
		j = i
		i += 1
if count < k:
	print(-1)
else:
	print(sum1)


(n, k) = map(int, input().split())
s = input()
l = []
for i in s:
	l.append(ord(i) - 96)
l.sort()
ans = chosen = min(l)
k -= 1
for i in l:
	if i >= chosen + 2:
		chosen = i
		ans += i
		k -= 1
	if k == 0:
		print(ans)
		exit(0)
print('-1')


from string import ascii_lowercase
(n, k) = map(int, input().split())
hasht = {}
for (i, c) in enumerate(ascii_lowercase):
	hasht[c] = i + 1
stage = input()
stage = sorted(stage)
final = ''
count = 0
hasht['first'] = -1
prev = 'first'
for ch in stage:
	if len(final) != k and hasht[ch] > hasht[prev] + 1:
		final += ch
		prev = ch
for c in final:
	count += hasht[c]
if len(final) != k:
	print(-1)
else:
	print(count)


(n, k) = map(int, input().split())
s = input()
nl = [chr(ord('a') + i) for i in range(26)]
vall = [0 for i in range(0, 26)]
for i in s:
	vall[ord(i) - ord('a')] += 1
j = 0
ans = 0
flag = 0
while j < 26:
	if vall[ord(nl[j]) - ord('a')] > 0:
		vall[ord(nl[j]) - ord('a')] -= 1
		ans += j + 1
		j += 2
		flag += 1
		if flag == k:
			break
	else:
		j += 1
		continue
if flag == k:
	print(ans)
else:
	print('-1')


(n, k) = map(int, input().split())
a = sorted(list(set(list(input()))))
ans = [ord(a[0]) - 96]
b = [a[0]]
for i in range(1, len(a)):
	if ord(a[i]) > ord(b[-1]) + 1:
		ans.append(ord(a[i]) - 96)
		b.append(a[i])
if len(ans) < k:
	print(-1)
else:
	print(sum(ans[:k]))


(n, k) = list(map(int, input().split(' ')))
s = sorted(input())
(sum, i, z) = (ord(s[0]) - 97 + 1, 1, s[0])
while i < n:
	if k <= 1:
		break
	if ord(s[i]) - 97 + 1 - (ord(z) - 97 + 1) >= 2:
		sum += ord(s[i]) - 97 + 1
		(z, k) = (s[i], k - 1)
	i += 1
print(sum if k <= 1 else -1)


(n, m) = map(int, input().split())
s = set(input())
s = list(s)
s.sort()
for i in range(len(s)):
	s[i] = ord(s[i]) - 96
count = 1
sum_ = s[0]
i = 0
j = 1
while 1:
	if count == m or j == len(s):
		break
	if s[j] - s[i] > 1:
		sum_ += s[j]
		i = j
		j = j + 1
		count += 1
	else:
		j = j + 1
if count != m:
	print(-1)
else:
	print(sum_)


(n, k) = map(int, input().split())
s = input()
s = list(s)
s.sort()
sum = ord(s[0]) - 96
c = ord(s[0]) - 96
prev = ord(s[0])
count = 1
for i in range(1, n):
	if count >= k:
		break
	elif ord(s[i]) > prev + 1:
		sum += ord(s[i]) - 96
		prev = ord(s[i])
		count += 1
if count >= k:
	print(sum)
else:
	print('-1')


(n, k) = map(int, input().split())
stages = list(input())
stages = sorted(stages)
main = [stages[0]]
comp = stages[0]
for i in range(1, n):
	if ord(comp) + 1 < ord(stages[i]):
		main.append(stages[i])
		comp = stages[i]
if len(main) < k:
	print('-1')
else:
	output = 0
	for i in range(k):
		output += ord(main[i]) - 96
	print(output)


(n, m) = map(int, input().split())
a = input()
arr = []
ans = []
f = True
for i in a:
	arr.append(ord(i) - 96)
arr = sorted(arr)
ans.append(arr[0])
for i in range(n):
	while arr[i] - ans[-1] < 2:
		if i < n - 1:
			i += 1
			f = True
		else:
			f = False
			break
	if len(ans) < m:
		if arr[i] not in ans and f == True:
			ans.append(arr[i])
	else:
		break
if len(ans) == m:
	print(sum(ans))
else:
	print(-1)


(n, k) = map(int, input().split())
s = input()
s = list(s)
s.sort()
f = lambda x: ord(x) - ord('a') + 1
tot = 10 ** 9
for i in range(n):
	ans = [s[i]]
	if len(ans) < k:
		for j in range(i + 1, n):
			if ord(s[j]) - ord(ans[-1]) > 1:
				ans.append(s[j])
			if len(ans) >= k:
				break
	if len(ans) >= k:
		tot = min(tot, sum(map(f, ans)))
if tot < 10 ** 9:
	print(tot)
else:
	print(-1)


(n, k) = map(int, input().split())
lst = sorted(input())
sm = ord(lst[0]) - 96
if k == 1:
	print(sm)
else:
	c = 0
	cnt = 1
	flag = 0
	for i in range(1, n):
		if ord(lst[i]) - ord(lst[c]) >= 2:
			sm += ord(lst[i]) - 96
			c = i
			cnt += 1
		if cnt == k:
			flag = flag + 1
			break
	if flag == 1:
		print(sm)
	else:
		print(-1)


import heapq
(n, k) = map(int, input().split())
nxt = 'a'
remaining = k
res = 0
s = list(input())
heapq.heapify(s)
while remaining and s:
	cur = heapq.heappop(s)
	if cur >= nxt:
		nxt = chr(ord(cur) + 2)
		res += ord(cur) + 1 - ord('a')
		remaining -= 1
if remaining:
	print('-1')
else:
	print(res)


(n, z) = list(map(int, input().split()))
s = input()
t = []
for k in s:
	t.append(ord(k) - 96)
t.sort()
if z == 1:
	print(t[0])
else:
	u = t[0]
	f = t[0]
	l = 1
	h = 0
	for d in range(1, len(t)):
		if l < z:
			if t[d] - f >= 2:
				u += t[d]
				f = t[d]
				l += 1
		else:
			print(u)
			h += 1
			break
	if h == 0:
		if l == z:
			print(u)
		else:
			print(-1)


(n, k) = map(int, input().split())
dicts = {chr(i + 96): i for i in range(1, 27)}
S = sorted(list((dicts[i] for i in input())))
ans = 0
ansC = k
prev = -2
flag = 0
for i in range(n):
	if S[i] > prev + 1 and k > 0:
		ans += S[i]
		prev = S[i]
		k -= 1
		flag += 1
if flag == ansC:
	print(ans)
else:
	print(-1)


inp = input().split(' ')
(n, k) = (int(inp[0]), int(inp[1]))
s = input()
arr = [False for x in range(30)]
for i in s:
	arr[ord(i) - 96] = True
(sum, count, i) = (0, 0, 1)
while i < 27:
	if arr[i] == True:
		sum += i
		count += 1
		i += 2
	else:
		i += 1
	if count == k:
		break
if count < k:
	print(-1)
else:
	print(sum)


def main():
	(n, m) = list(map(int, input().split()))
	st = input()
	a = [0] * n
	for i in range(n):
		a[i] = ord(st[i]) - 96
	a.sort()
	ans = 0
	last = -1
	c = 0
	for i in range(n):
		if a[i] - last >= 2:
			c += 1
			last = a[i]
			ans += a[i]
		if c == m:
			print(ans)
			return
	print(-1)
main()


(a, b) = map(int, input().split())
s = sorted(input())
last = '$'
cost = 0
used = 0
for c in s:
	if ord(c) - ord(last) > 1:
		cost += ord(c) - ord('a') + 1
		used += 1
		last = c
	if used == b:
		break
if used == b:
	print(cost)
else:
	print(-1)


entrada = input()
n = int(entrada.split(' ')[0])
k = int(entrada.split(' ')[1])
stages = input()
alphabet = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
stages = list(stages)
stages.sort()
cnt = alphabet[stages[0]]
k = k - 1
j = 0
i = 1
while i < n:
	if k <= 0:
		break
	if alphabet[stages[i]] - alphabet[stages[j]] >= 2:
		cnt += alphabet[stages[i]]
		k = k - 1
		j = i
	i = i + 1
if k <= 0:
	print(cnt)
else:
	print('-1')


def transform(x):
	return int(x)

def splitString(string):
	characters = []
	size = len(string)
	i = 0
	while i < size:
		if string[i] not in characters:
			characters.append(string[i])
		i += 1
	return characters

def sumOfStages(alphabetMap, rocket):
	result = 0
	for stage in rocket:
		result += alphabetMap[stage]
	return result

def createAlphabetMap():
	alphabetMap = {}
	alphabet = list('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'.split())
	i = 1
	for letter in alphabet:
		alphabetMap[letter] = i
		i += 1
	return alphabetMap
(n, k) = tuple(map(transform, input().split()))
s = splitString(input())
alphabetMap = createAlphabetMap()
sortedS = sorted(s)
rocket = []
for stage in sortedS:
	charactersArraySize = len(rocket)
	if charactersArraySize != 0 and charactersArraySize < k:
		if alphabetMap[stage] >= alphabetMap[rocket[charactersArraySize - 1]] + 2:
			rocket.append(stage)
	elif charactersArraySize < k:
		rocket.append(stage)
if len(rocket) < k:
	print(str(-1))
else:
	result = sumOfStages(alphabetMap, rocket)
	print(result)


(n, k) = map(int, input().split())
s = input()
has = [ord(el) - 96 for el in sorted(s)]
ans = has[0]
last = ans
done = 1
i = 1
while i < n and done < k:
	if has[i] - 2 >= last:
		ans += has[i]
		last = has[i]
		done += 1
	i += 1
if done == k:
	print(ans)
else:
	print(-1)


(n, m) = map(int, input().split(' '))
s = input()
s = sorted(s)
j = c = sum1 = 0
f = 0
if m > n:
	print('-1')
elif m == 1:
	print(ord(s[0]) - 96)
else:
	sum1 = ord(s[0]) - 96
	c = 1
	for i in range(len(s) - 1):
		if ord(s[i + 1]) - ord(s[j]) > 1:
			sum1 += ord(s[i + 1]) - 96
			c += 1
			j = i + 1
		if c == m:
			f = 1
			break
	if f == 1:
		print(sum1)
	else:
		print('-1')


in1 = input()
in2 = input()
(n, k) = in1.strip('\n').split(' ')
s = in2.strip('\n')
k = int(k)
x = []
for i in range(26):
	temp = chr(ord('a') + i)
	if s.find(temp) != -1:
		x.append((temp, 1))
	else:
		x.append((temp, 0))
pre = -2
count = 0
end = 0
for i in range(1, k + 1):
	for j in range(26):
		(ch, tg) = x[j]
		if tg == 0 and j != 25:
			continue
		elif tg == 1:
			if j - pre < 2 and j != 25:
				continue
			elif j - pre >= 2:
				x[j] = (ch, 0)
				count += j + 1
				pre = j
				break
		end = 1
	if end == 1:
		count = -1
		break
print(count)


from collections import defaultdict
import string
(n, k) = [int(i) for i in input().split()]
x = input()
d = {}
for i in string.ascii_lowercase:
	d[i] = i in x
i = 0
count = 0
while i < 26 and k > 0:
	if d[string.ascii_lowercase[i]]:
		count += i + 1
		i += 2
		k -= 1
	else:
		i += 1
if k > 0:
	print(-1)
else:
	print(count)


(n, k) = map(int, input().split())
u = list(input())
c = 96
for i in range(n):
	u[i] = ord(u[i]) - 96
u.sort()
ans = 0
d = -3
cnt = 0
for i in range(n):
	if u[i] > d + 1:
		ans += u[i]
		d = u[i]
		cnt += 1
		if cnt == k:
			break
if cnt == k:
	print(ans)
else:
	print(-1)


(n, k) = map(int, input().split())
alist = list(input())
alist2 = []
alist.sort()
if k == 1:
	print(ord(alist[0]) - 96)
else:
	leng = len(alist)
	j = 1
	i = 0
	while i < leng - 1 and j < leng:
		if ord(alist[j]) - ord(alist[i]) >= 2 and j:
			alist2.append(alist[j])
			alist2.append(alist[i])
			i = j
			j = j + 1
		else:
			j = j + 1
	anewlist = list(set(alist2))
	anewlist.sort()
	sum = 0
	if len(anewlist) >= k:
		anewlist.sort()
		for i in range(0, k):
			sum = sum + (ord(anewlist[i]) - 96)
		print(sum)
	else:
		print(-1)


(n, k) = map(int, input().split(' '))
s = list(input())
asci = [ord(x) for x in s]
asci.sort()
alist = []
flag = 1
for i in range(n):
	if flag:
		stages = []
		stages.append(asci[i])
		prev = i
		rlen = 1
		for j in range(i + 1, n):
			if rlen == k:
				alist = stages[:]
				flag = 0
				break
			if asci[j] - asci[prev] > 1:
				stages.append(asci[j])
				prev = j
				rlen = rlen + 1
				if rlen == k:
					alist = stages[:]
					flag = 0
					break
	else:
		break
if len(alist) == k:
	s = 0
	for i in range(k):
		s = s + alist[i] - 96
	print(s)
elif k == 1:
	print(asci[0] - 96)
else:
	print(-1)


(n, k) = list(map(int, input().split()))
L = []
str1 = input()
for j in str1:
	L.append(ord(j) - 96)
L.sort()
s = L[0]
s1 = L[0]
p = 1
q = 1
while q < n and p < k:
	if L[q] - s1 > 1:
		s += L[q]
		p += 1
		s1 = L[q]
	q += 1
if p == k:
	print(s)
else:
	print(-1)


x = input()
(n, k) = list(map(int, x.split()))
foo = input()
st = sorted(foo)
num = []
ans = 1000000
lnt = len(st)
for i in st:
	num.append(ord(i) - 96)
for i in range(0, lnt):
	cnt = 1
	prev = num[i]
	wt = prev
	if cnt == k:
		ans = min(ans, wt)
	else:
		for j in range(i + 1, lnt):
			if num[j] - prev > 1:
				cnt = cnt + 1
				wt = wt + num[j]
				prev = num[j]
				if cnt == k:
					break
		if cnt == k:
			ans = min(ans, wt)
if ans == 1000000:
	print(-1)
else:
	print(ans)


nk = input().split()
n = int(nk[0])
k = int(nk[1])
mod = input()
modulos = [m for m in mod]
modUnico = list(set(modulos))
modulos = sorted(modUnico)

def constroiFoguete(k, modulos):
	soma = 0
	ultimo = -1
	faltam = k
	for m in modulos:
		num = ord(m) - 96
		if num > ultimo + 1:
			soma += num
			faltam -= 1
			ultimo = num
		if faltam == 0:
			return soma
	return -1
print(constroiFoguete(k, modulos))


(stor_size, steps_nr) = (int(x) for x in input().split())
storage = sorted(list(input()))
best_weight = 1000000000.0
for start_idx in range(stor_size):
	curr_weight = 0
	curr_last = 'A'
	length = 0
	for letter in storage[start_idx:]:
		if ord(letter) - ord(curr_last) >= 2:
			curr_weight += ord(letter) - ord('a') + 1
			curr_last = letter
			length += 1
		if length == steps_nr:
			break
	if length == steps_nr:
		best_weight = min(curr_weight, best_weight)
if best_weight == 1000000000.0:
	best_weight = -1
print(best_weight)


(n, k) = map(int, input().split())
s = input()
L = [ord(s[i]) - ord('a') + 1 for i in range(n)]
L = sorted(set(L))
(i, j, f) = (0, 1, 0)
p = L[i]
k = k - 1
while k > 0 and j < len(L):
	if L[j] - L[i] > 1:
		p = p + L[j]
		i = j
		k -= 1
	j += 1
if k == 0:
	print(p)
else:
	print(-1)


f = lambda : map(int, input().split())
(n, k) = f()
s = []
for i in input():
	s.append(i)
s.sort()
res = [s[0]]
result = ord(s[0]) - 96
l = True
for i in range(1, n):
	if len(res) == k:
		print(result)
		l = False
		break
	if ord(res[-1]) + 2 <= ord(s[i]):
		res.append(s[i])
		result += ord(s[i]) - 96
if l and len(res) == k:
	print(result)
if len(res) < k:
	print(-1)


def convert_text_to_array(text):
	result_array = []
	for char in text:
		result_array.append(char)
	return result_array

def get_char_weight(char):
	return ord(char) - 96

def main():
	first_input = input()
	second_input = input()
	max_quantity = int(first_input.split(' ')[1])
	array = convert_text_to_array(second_input)
	array.sort()
	last_stage = ' '
	weight_sum = 0
	stage_flow = ''
	stages_number = 0
	for (index, stage) in enumerate(array):
		if get_char_weight(stage) - get_char_weight(last_stage) > 1:
			last_stage = stage
			weight_sum += get_char_weight(stage)
			stages_number += 1
			stage_flow += stage
		if stages_number >= max_quantity:
			break
		if index == len(array) - 1 and stages_number != max_quantity:
			weight_sum = -1
	print(weight_sum)
	return
main()


(n, k) = map(int, input().split())
s = input()
a = []
for i in s:
	a.append(i)
a.sort()
alh = 'abcdefghijklmnopqrstuvwxyz'
s = 0
k1 = 0
z = -1
for i in range(n):
	if k1 != k:
		if alh.index(a[i]) > z:
			z = alh.index(a[i]) + 1
			s += alh.index(a[i]) + 1
			k1 += 1
if k1 != k:
	print(-1)
else:
	print(s)


(n, k) = map(int, input().split())
a = sorted([ord(c) - 96 for c in input()])
res = 0
cnt = 0
prev = -1
for e in a:
	if e >= prev + 2 and cnt < k:
		cnt += 1
		res += e
		prev = e
print(res if cnt == k else -1)


(a, b) = map(int, input().split())
c = input()
d = [ord(e) - 96 for e in c]
d.sort()
totVal = 0
stageVal = -1
stageCount = 0
for stageIndex in range(a):
	if d[stageIndex] >= stageVal + 2:
		stageVal = d[stageIndex]
		totVal += d[stageIndex]
		stageCount += 1
		if stageCount == b:
			print(totVal)
			break
else:
	print(-1)


import math
(n, k) = list(map(int, input().split()))
str = input()
l = []
for elem in str:
	l.append(elem)
l.sort()
stup = chr(97 - 2)
x = 0
xc = 0
flag = True
for i in range(n):
	if ord(stup) + 1 < ord(l[i]):
		x += 1
		xc += ord(l[i]) - 96
		stup = l[i]
		if x == k:
			print(xc)
			flag = False
			break
if flag:
	print(-1)


s1 = input()
s1 = list(map(int, s1.split()))
(n, k) = (s1[0], s1[1])
s = input()
arr = list()
for i in s:
	arr.append(ord(i) - 96)
arr = sorted(arr)
(count, prev, i) = (1, arr[0], 1)
ans = prev
while i < len(arr):
	if count == k:
		break
	if arr[i] == prev or arr[i] == prev + 1:
		i += 1
	else:
		ans += arr[i]
		prev = arr[i]
		i += 1
		count += 1
if count == k:
	print(ans)
else:
	print(-1)


def mi():
	return map(int, input().split())
(n, k) = mi()
s = sorted(list(set(list(input()))))
c = ord(s[0]) - 97 + 1
lastchar = s[0]
cnt = 1
for i in range(1, len(s)):
	if cnt == k:
		break
	if ord(s[i]) - ord(lastchar) > 1:
		lastchar = s[i]
		c += ord(lastchar) - 97 + 1
		cnt += 1
if cnt != k:
	print(-1)
else:
	print(c)


(n, k) = map(int, input().split())
ans = 0
s = input()
b = sorted(s)
pr = -1
summ = 0
for i in range(len(b)):
	if ord(b[i]) > pr + 1:
		summ += ord(b[i]) - ord('a') + 1
		ans += 1
		if ans == k:
			break
		pr = ord(b[i])
if ans >= k:
	print(summ)
else:
	print(-1)


(n, k) = map(int, input().split())
l = list(input())
l.sort()
res = ord(l[0]) - ord('a') + 1
prev = l[0]
k = k - 1
i = 1
while i < n and k > 0:
	if ord(l[i]) - ord(prev) > 1 and k > 0:
		res += ord(l[i]) - ord('a') + 1
		prev = l[i]
		k -= 1
	i += 1
if k > 0:
	print(-1)
else:
	print(res)


from functools import reduce
(n, k) = map(int, input().split())
s = input()
filte = sorted(set(s))
res = list('0')
for i in range(len(filte)):
	if ord(res[-1]) != ord(filte[i]) - 1:
		res += filte[i]
		k -= 1
	if k == 0:
		break
if k == 0:
	print(reduce(lambda x, y: x + ord(y) - 96, res[1:], 0))
else:
	print(-1)


(n, k) = map(int, input().split())
s = list(map(ord, sorted(input())))
s = list(map(lambda x: x - 96, s))
totalwgt = 0
totalnum = 0
last = -1
for i in s:
	if totalnum < k:
		if i > last + 1:
			totalnum += 1
			totalwgt += i
			last = i
	else:
		break
if totalnum == k:
	print(totalwgt)
else:
	print(-1)


(n, k) = map(int, input().split())
a = sorted([ord(x) - 96 for x in input()])
s1 = 0
i = 0
c1 = 0
last = -2
while i < n and c1 < k:
	if a[i] - last > 1:
		s1 += a[i]
		last = a[i]
		c1 += 1
	i += 1
s2 = 0
i = 0
c2 = 0
last = -1
while i < n and c2 < k:
	if a[i] - last > 1:
		s2 += a[i]
		last = a[i]
		c2 += 1
	i += 1
if c1 < k:
	if c2 < k:
		print(-1)
	else:
		print(s2)
elif c2 < k:
	print(s1)
else:
	print(min(s1, s2))


nk = input().split(' ')
k = int(nk[1])
row = input()
seti = []
for i in range(len(row)):
	seti.append(ord(row[i]) - 96)
seti.sort()
sum1 = seti[0]
last = seti[0]
cout = 1
for i in range(1, len(seti)):
	if seti[i] > last + 1 and cout < k:
		last = seti[i]
		sum1 = sum1 + int(seti[i])
		cout = cout + 1
if cout < k:
	print(-1)
else:
	print(sum1)


(n, k) = map(int, input().strip().split(' '))
s = list(input())
s.sort()
w = 0
c = 0
ls = ''
for i in s:
	if c == 0:
		w += ord(i) - ord('a') + 1
		ls = i
		c += 1
	elif abs(ord(ls) - ord(i)) >= 2:
		w += ord(i) - ord('a') + 1
		ls = i
		c += 1
	if c == k:
		break
if c == k:
	print(w)
else:
	print(-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', 'hh', 'kk']
(n, k) = map(int, input().split())
b = list(map(str, input()))
b.sort()
v = []
m = []
w = 0
for i in b:
	if not i in v:
		v.append(i)
a = 'kk'
for i in v:
	if abs(q.index(a) - q.index(i)) >= 2:
		m.append(i)
		a = i
if len(m) >= k:
	for i in range(k):
		w += q.index(m[i])
		w += 1
	print(w)
else:
	print(-1)


import sys
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']
(n, k) = input().split()
(n, k) = (int(n), int(k))
a = input()
a = list(a)
ind = []
for i in range(n):
	ind.append(alph.index(a[i]) + 1)
ind2 = []
for i in range(n):
	ind2.append([ind[i], a[i]])
ind2.sort()
s = []
f = 0
flag = True
s.append(ind2[0][0])
if n == 1 and k == 1:
	print(ind2[0][0])
	sys.exit()
for i in range(1, n):
	if len(s) == k:
		print(sum(s))
		sys.exit()
	if ind2[i][0] == s[-1] or ind2[i][0] - s[-1] == 1:
		continue
	else:
		s.append(ind2[i][0])
if len(s) == k:
	print(sum(s))
	sys.exit()
print(-1)


ALF = 'abcdefghijklmnopqrstuvwxyz'
(n, k) = map(int, input().split())
s = list(input())
s.sort()
res = float('+inf')
temp = ''
for m in s:
	temp = m
	for i in s:
		if ALF.find(i) - ALF.find(temp[-1]) >= 2:
			temp = temp + i
		if len(temp) == k:
			temp2 = 0
			for j in temp:
				temp2 += ALF.find(j) + 1
			if temp2 < res:
				res = temp2
if res == float('+inf'):
	print('-1')
else:
	print(res)


n = list(map(int, input().split()))
s = input()
t = []
tx = set()
for i in s:
	tx.add(ord(i) - 96)
for i in tx:
	t.append(i)
t.sort()
mini = []
l = 0
z = 0
w = 0
while len(t) > 0:
	mini = 30
	for i in range(len(t)):
		if mini > t[i]:
			if t[i] > w + 1 or w == 0:
				mini = t[i]
				t.remove(t[i])
				l += 1
				z += mini
				w = mini
				if l == n[1]:
					print(z)
					exit()
				break
	if mini == 30 or len(t) == 0:
		print(-1)
		exit()


(n, k) = list(map(int, input().split()))
s = [i for i in input()]
s = sorted(set(s))
last = s[0]
minz = ord(s[0]) - 96
k -= 1
for i in range(1, len(s)):
	if k == 0:
		break
	if ord(s[i]) - ord(last) > 1:
		last = s[i]
		minz += ord(s[i]) - 96
		k -= 1
print(minz if k == 0 else -1)


from bisect import bisect
from collections import defaultdict
from math import gcd, sqrt, ceil, inf
from collections import Counter
import sys
sys.setrecursionlimit(1000000)
from bisect import bisect
from collections import defaultdict
from math import gcd, sqrt, ceil, inf, factorial, log2
from collections import Counter
import sys
sys.setrecursionlimit(10 ** 9)
mini = 10 ** 18

def solve(cur, i, cnt, sumi):
	global mini
	if i == n:
		return
	if cnt == k:
		mini = min(mini, sumi)
	for j in range(i + 1, n):
		if ord(s[j]) - ord(cur) >= 2:
			solve(s[j], j, cnt + 1, sumi + ord(s[j]) - 97 + 1)
(n, k) = map(int, input().split())
s = list(input())
ans = 10 ** 18
s.sort()
z = solve(s[0], 0, 1, ord(s[0]) - 97 + 1)
if mini == 10 ** 18:
	print(-1)
else:
	print(mini)


(n, k) = map(int, input().split())
s = set(list(input()))
sorted = list(sorted(s))
ans = list()
for c in sorted:
	if len(ans) == 0:
		ans.append(c)
	elif ord(ans[-1]) + 1 != ord(c):
		ans.append(c)
if len(ans) < k:
	print(-1)
else:
	print(sum([ord(x) - ord('a') + 1 for x in ans[:k]]))


b = input().split()
n = int(b[0])
k = int(b[1])
s = input()
res = []
sum = 0
for letter in sorted(list(s)):
	if len(res) == k:
		break
	if len(res) == 0 or ord(letter) - ord(res[-1]) >= 2:
		res.append(letter)
		sum += ord(letter) - ord('a') + 1
if len(res) == k:
	print(sum)
else:
	print(-1)


(n, k) = map(int, input().split())
s = list(input())
s.sort()
freq = [0 for i in range(26)]
for i in range(n):
	freq[ord(s[i]) - 97] += 1
c = 0
ans = 0
pr = -2
for i in range(26):
	if freq[i] != 0 and i - pr >= 2:
		c += 1
		ans += i
		pr = i
		if c == k:
			break
if c == k:
	print(ans + k)
else:
	print(-1)


import sys
import bisect
from collections import Counter
read_int = lambda : int(sys.stdin.readline())
read_ints = lambda : 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 = sorted(list(set([ord(l) - ord('a') + 1 for l in read()])))
	(res, tmp) = (s[0], s[0])
	for i in range(1, len(s)):
		if tmp + 1 == s[i]:
			continue
		elif k == 1:
			break
		else:
			res += s[i]
			tmp = s[i]
			k -= 1
	print(res if k == 1 else -1)
main()


def f(a):
	return ord(a) - 96
(n, k) = map(lambda x: int(x), input().split())
stages = list(input())
stages.sort()
cur_sumbol = f(stages[0])
cur_pnt = 0
cur_length = 1
cur_w = f(stages[0])
flag = True
while cur_length < k:
	while f(stages[cur_pnt]) - 2 < cur_sumbol:
		cur_pnt += 1
		if cur_pnt == len(stages):
			print(-1)
			flag = False
			break
		continue
	if not flag:
		break
	cur_w += f(stages[cur_pnt])
	cur_sumbol = f(stages[cur_pnt])
	cur_length += 1
if flag:
	print(cur_w)


(n, k) = map(int, input().split())
s = str(input())
s = list(s)
s.sort()
s = [ord(c) - ord('a') + 1 for c in s]
ans = []
for c in s:
	if not ans:
		ans.append(c)
	elif c - ans[-1] >= 2:
		ans.append(c)
	if len(ans) == k:
		break
if len(ans) == k:
	print(sum(ans))
else:
	print(-1)


(n, k) = map(int, input().split())
s = list(input())
s.sort()
cnt = 1
weight = ord(s[0]) - 96
ps = 0
if k > 1:
	for i in range(1, n):
		if ord(s[i]) - ord(s[ps]) >= 2:
			cnt += 1
			ps = i
			weight += ord(s[i]) - 96
		if cnt == k:
			break
if cnt == k:
	print(weight)
else:
	print(-1)


(n, k) = list(map(int, input().split()))
s = list(input())
s.sort()
flag = True

def checkletters(a, b):
	return ord(b) - ord(a) >= 2

def weight(l):
	return sum(map(lambda x: ord(x) - ord('a') + 1, l))
current_list = []
for x in s:
	if len(current_list) == 0 or checkletters(current_list[-1], x):
		current_list.append(x)
	if len(current_list) == k:
		break
else:
	print(-1)
	flag = False
if flag:
	print(weight(current_list))


R = lambda : map(int, input().split())
(n, m) = R()
s = sorted(map(ord, input()))
val = s[:1]
for c in s[1:]:
	if c > val[-1] + 1:
		val.append(c)
print(-1 if len(val) < m else sum(val[:m]) - 96 * m)


(n, k) = map(int, input().split())
s = input()
cnt = {}
for i in range(n):
	cnt[ord(s[i]) - ord('a')] = cnt.get(ord(s[i]) - ord('a'), 0) + 1
res = ''
ans = 0
i = 0
while i < 26:
	if cnt.get(i, 0) > 0:
		ans += i + 1
		res += chr(i + ord('a'))
		i += 1
	i += 1
	if len(res) == k:
		break
if len(res) == k:
	print(ans)
else:
	print(-1)


import sys
import os

def solve(stages, k):
	s = dict()
	for char in stages:
		s[ord(char) - ord('a')] = True
	weight = 0
	current = 0
	last = -2
	for i in range(26):
		if i in s:
			if i >= last + 2:
				weight += i + 1
				current += 1
				last = i
		if current == k:
			break
	return -1 if current < k else weight

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


(n, k) = map(int, input().split())
c = l = r = 0
for x in sorted(map(ord, input())):
	if x > l + 1:
		c += 1
		l = x
		r += x - ord('a') + 1
	if c == k:
		break
print([r, -1][c < k])


n = input().split()
k = int(n[1])
n = int(n[0])
s = input()
l = []
w = []
for i in range(27):
	w.append(False)
for i in s:
	w[ord(i) - 96] = True
for i in range(27):
	if w[i]:
		l.append(i)
l.sort()
i = 1
a = 0
m = l[0]
last = m
f = True
while i < k:
	if a + 2 <= len(l):
		if l[a + 1] - l[a] > 1:
			i += 1
			a += 1
			last = l[a]
			m += last
		elif a + 3 <= len(l):
			i += 1
			a += 2
			last = l[a]
			m += last
		else:
			print('-1')
			f = False
			break
	else:
		print('-1')
		f = False
		break
if f:
	print(m * f)


(n, k) = [int(x) for x in input().split()]
s = {ord(x) - 96 for x in input()}
r = sorted(s)
min_sum = -1
count = 1
current_sum = r[0]
prev_item = r[0]
for (i, item) in enumerate(r[1:]):
	if count == k:
		break
	if item - prev_item > 1:
		count += 1
		current_sum += item
		prev_item = item
if count == k:
	min_sum = current_sum
print(min_sum)


(n, k) = map(int, input().split(' '))
s = input()
a = []
b = []
for i in range(len(s)):
	a.append(ord(s[i]))
a.sort()
b.append(a[0])
j = 0
for i in a:
	if i != b[j]:
		j += 1
		b.append(i)
x = 0
s1 = 0
flag = 0
k1 = k
p = 0
q = 0
if len(b) < k:
	print('-1')
elif len(b) == 1 and k == 1:
	print(b[0] - 96)
else:
	while k > 0:
		if x == 0:
			s1 += b[x] - 96
			flag += 1
			p = 0
			k = k - 1
		else:
			d = b[x] - b[p]
			if d > 1:
				s1 += b[x] - 96
				flag += 1
				p = x
				k = k - 1
		x += 1
		if flag == k1:
			print(s1)
			q += 1
			break
		if x == len(b):
			print('-1')
			q += 1
			break
	if q == 0:
		print('-1')


(*k,) = map(int, input().split())
str = sorted([ord(c) - 96 for c in input()])
ans = [str[0]]
for i in range(1, len(str)):
	if str[i] - ans[-1] > 1:
		ans.append(str[i])
print(-1 if len(ans) < k[1] else sum(ans[:k[1]]))


(n, k) = map(int, input().split())
s = [i for i in input()]
s = set(s)
s = list(s)
s.sort()
ans = 'z'
answer = 0
i = 0
test = 0
while k != 0:
	if ord(s[i]) != ord(ans[-1]) + 1:
		ans = ans + s[i]
		answer = answer + ord(s[i]) - 96
		k = k - 1
	i = i + 1
	if i >= len(s) and k != 0:
		test = 1
		break
if test == 1:
	print(-1)
else:
	print(answer)


def main():
	(n, k) = map(int, input().split())
	s = list(sorted(set(map(ord, [i for i in input()]))))
	n = len(s)
	ind = 1
	k = k - 1
	ret = s[0] - 96
	while k and ind < n:
		if s[ind] - 1 > s[ind - 1]:
			ret += s[ind] - 96
		elif ind + 1 >= n:
			print(-1)
			return 0
		else:
			ret += s[ind + 1] - 96
			ind += 1
		ind += 1
		k -= 1
	if k:
		print(-1)
		return 0
	print(ret)
	return 0
main()


t = 1
for test in range(t):
	(n, k) = map(int, input().split())
	s = set(list(input()))
	s = list(s)
	s.sort()
	ans = 0
	prev = 95
	for i in s:
		if ord(i) - prev >= 2:
			ans += ord(i) - 96
			k -= 1
			prev = ord(i)
		if k == 0:
			break
	if k > 0:
		print(-1)
	else:
		print(ans)


([n, k], s) = (map(int, input().split()), sorted([ord(c) - ord('a') + 1 for c in set(input())]))
for i in range(1, len(s)):
	if s[i] - s[i - 1] < 2:
		s[i] = 0
s = sorted(set(s))
if s[0] == 0:
	s = s[1:]
print(sum(s[:k]) if len(s) >= k else -1)


import sys
alphabet = 'abcdefghijklmnopqrstuvwxyz'
weights = {}
for i in range(26):
	weights[alphabet[i]] = i + 1
(n, k) = sys.stdin.readline().split(' ')
(n, k) = (int(n), int(k))
s = sys.stdin.readline().strip('\n')
rs = []
for i in s:
	if weights[i] not in rs:
		rs.append(weights[i])
if len(rs) < k:
	print(-1)
	sys.exit(0)
else:
	rs = sorted(rs)
	used = 0
	weight = 0
	last = -1
	for i in rs:
		if i - last > 1:
			last = i
			weight += i
			used += 1
			if used == k:
				print(weight)
				sys.exit(0)
print(-1)


(n, k) = map(int, input().split())
A = list(input())
A.sort(reverse=True)
an = ord(A.pop()) - 96
a = 1
l = an
while A and a < k:
	ne = ord(A.pop()) - 96
	if ne - l <= 1:
		continue
	else:
		an += ne
		l = ne
		a += 1
if a < k:
	print(-1)
else:
	print(an)


(n, k) = map(int, input().split())
s = input()
s = ''.join(sorted(s))
k -= 1
prev = s[0]
ans = ord(s[0]) - ord('a') + 1
for i in range(n):
	if k == 0:
		break
	if ord(s[i]) - ord(prev) > 1:
		k -= 1
		ans += ord(s[i]) - ord('a') + 1
		prev = s[i]
if k:
	ans = -1
print(ans)


from string import ascii_lowercase as l
(n, k) = map(int, input().split())
arr = sorted(list(map(lambda a: l.index(a) + 1, input())))

def haha(n, k, arr):
	if k == 1:
		return arr[0]
	sumi = 0
	cur = -1
	for num in range(0, n):
		if k == 0:
			break
		if arr[num] - cur >= 2:
			sumi += arr[num]
			k -= 1
			cur = arr[num]
	if k == 0:
		return sumi
	return -1
print(haha(n, k, arr))


(n, k) = map(int, input().split())
s = set(input())
st = ''
p = []
k1 = 1
if k <= len(s):
	for i in s:
		p.append(i)
	p.sort()
	st = ''.join(p)
	h = ord(st[0]) - 96
	j = 0
	i = 0
	while k1 < k and i < len(st) - 1:
		if ord(st[i + 1]) - ord(st[j]) >= 2:
			h += ord(st[i + 1]) - 96
			j = i + 1
			k1 += 1
		i += 1
	if k1 == k:
		print(h)
	else:
		print(-1)
else:
	print(-1)


(n, k) = map(int, input().split())
tak = input()
tab = []
for x in range(len(tak)):
	if tak[x] == 'a':
		tab.append(1)
	elif tak[x] == 'b':
		tab.append(2)
	elif tak[x] == 'c':
		tab.append(3)
	elif tak[x] == 'd':
		tab.append(4)
	elif tak[x] == 'e':
		tab.append(5)
	elif tak[x] == 'f':
		tab.append(6)
	elif tak[x] == 'g':
		tab.append(7)
	elif tak[x] == 'h':
		tab.append(8)
	elif tak[x] == 'i':
		tab.append(9)
	elif tak[x] == 'j':
		tab.append(10)
	elif tak[x] == 'k':
		tab.append(11)
	elif tak[x] == 'l':
		tab.append(12)
	elif tak[x] == 'm':
		tab.append(13)
	elif tak[x] == 'n':
		tab.append(14)
	elif tak[x] == 'o':
		tab.append(15)
	elif tak[x] == 'p':
		tab.append(16)
	elif tak[x] == 'q':
		tab.append(17)
	elif tak[x] == 'r':
		tab.append(18)
	elif tak[x] == 's':
		tab.append(19)
	elif tak[x] == 't':
		tab.append(20)
	elif tak[x] == 'u':
		tab.append(21)
	elif tak[x] == 'v':
		tab.append(22)
	elif tak[x] == 'w':
		tab.append(23)
	elif tak[x] == 'x':
		tab.append(24)
	elif tak[x] == 'y':
		tab.append(25)
	elif tak[x] == 'z':
		tab.append(26)
tab.sort()
tab1 = []
tab1.append(tab[0])
for x in range(len(tab) - 1):
	if tab[x + 1] - tab[x] >= 2:
		tab1.append(tab[x + 1])
	elif tab[x + 1] - tab1[len(tab1) - 1] > 1:
		tab1.append(tab[x + 1])
wynik = 0
try:
	for x in range(k):
		wynik += tab1[x]
	print(wynik)
except IndexError:
	print('-1')


(n, k) = map(int, input().split())
s = sorted(set(input()))
x = s[0]
st = ord('a') - 1
ans = ord(x) - st
cnt = 1
for i in range(1, len(s)):
	if cnt == k:
		break
	if ord(s[i]) - ord(x) > 1:
		x = s[i]
		ans += ord(x) - st
		cnt += 1
if cnt == k:
	print(ans)
else:
	print(-1)


(n, k) = list(map(int, input().split()))
stages = input()
stages = sorted(stages)
w = ord(stages[0]) - (ord('a') - 1)
k -= 1
current_possible = ord(stages[0]) + 2
stages = stages[1:]
while k and len(stages) > 0:
	if ord(stages[0]) >= current_possible:
		k -= 1
		current_possible = ord(stages[0]) + 2
		w += ord(stages[0]) - (ord('a') - 1)
		stages = stages[1:]
	else:
		stages = stages[1:]
if k == 0:
	print(w)
else:
	print(-1)


import string
AAA = list(string.ascii_lowercase)
(n, k) = list(map(int, input().split()))
a = sorted(list(input()))
result = list()
result.append(a.pop(0))
cnt = k
k -= 1
while k > 0:
	if len(a) == 0:
		break
	if AAA.index(a[0]) - AAA.index(result[-1]) > 1:
		result.append(a.pop(0))
		k -= 1
	else:
		a.pop(0)
if len(result) != cnt:
	print(-1)
else:
	res = 0
	for i in result:
		res += AAA.index(i) + 1
	print(res)


import sys
(n, m) = map(int, input().split())
a = input()
a = list(map(lambda x: ord(x) - ord('a') + 1, a))
a.sort()
cnt = -1
res = 0
flag = True
index = 0
while m > 0:
	if index == len(a):
		print(-1)
		flag = False
		break
	if a[index] > cnt + 1:
		res += a[index]
		cnt = a[index]
		m -= 1
	index += 1
if flag:
	print(res)


(n, l) = map(int, input().split())
s = set(input())
chars = sorted([ord(c) - 96 for c in s])
total = 0
last = -1
for c in chars:
	if c >= last + 2:
		total += c
		last = c
		l -= 1
	if l == 0:
		break
if l == 0:
	print(total)
else:
	print(-1)


(n, m) = map(int, input().split())
x = input()
l = []
for i in range(len(x)):
	l.append(ord(x[i]))
l.sort()
j = 1
count = 1
sumi = [l[0]]
while j < len(x) and count < m:
	if l[j] - sumi[-1] >= 2:
		count += 1
		sumi.append(l[j])
		j += 1
	else:
		j += 1
if count < m:
	print(-1)
else:
	print(sum(sumi) - 96 * m)


(n, k) = map(int, input().split())
s = input()
l = []
for i in s:
	l.append(ord(i) - ord('a'))
l = list(set(l))
l.sort()
a = [l[0]]
n = len(l)
for i in range(1, n):
	if l[i - 1] in a:
		if l[i] - l[i - 1] >= 2:
			a.append(l[i])
	else:
		a.append(l[i])
a.sort()
ct = 0
if len(a) < k:
	print(-1)
else:
	for i in range(k):
		ct += a[i] + 1
	print(ct)


alpha = []
for m in range(1, 27):
	alpha.append((m, chr(ord('a') + m - 1)))
ent1 = input().split()
n = int(ent1[0])
k = int(ent1[1])
parts = list(input())

def sort(sub_li):
	sub_li.sort(key=lambda x: x[1])
	return sub_li
parts_w = []
for p in parts:
	for a in alpha:
		if a[1] == p and a not in parts_w:
			parts_w.append(a)
ordered = sort(parts_w)
unwanted = []
for i in range(0, len(ordered) - 1):
	if ordered[i][0] + 1 == ordered[i + 1][0] and ordered[i][0] not in unwanted:
		unwanted.append(ordered[i + 1][0])
if len(ordered) - len(unwanted) < k:
	print('-1')
else:
	total = 0
	a = 0
	count = 0
	while a < k + len(unwanted):
		if ordered[a][0] not in unwanted:
			total += ordered[a][0]
			count += 1
			if count == k:
				break
		a += 1
	print(total)


(n, k) = map(int, input().split())
s = sorted(set(input()))
t = s[0]
for i in range(1, len(s)):
	if ord(s[i]) - ord(t[-1]) > 1:
		t += s[i]
if len(t) < k:
	print(-1)
else:
	ans = 0
	for i in range(k):
		ans += ord(t[i]) - ord('a') + 1
	print(ans)


import math as ma
from sys import exit
from decimal import Decimal as dec

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

def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x

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

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mi = 1000000000
(n, k) = num()
s = input()
f = [0] * 26
for i in range(n):
	a = ord(s[i]) - 97
	f[a] += 1
ss = 0
pp = 0
ind = 0
for i in range(26):
	if f[i] == 0:
		continue
	ss = i + 1
	pp = 1
	ind = i + 2
	while pp < k and ind < 26:
		if f[ind] == 0:
			ind += 1
		else:
			ss += ind + 1
			pp += 1
			ind += 2
	if pp == k:
		mi = min(ss, mi)
if mi == 1000000000:
	print(-1)
else:
	print(mi)


(n, k) = [int(x) for x in input().split()]
a = input()
a = sorted(a)
flag = 0
mina = 100000000
for i in range(0, n):
	num = ord(a[i])
	suma = num - 96
	c = 1
	check = 0
	for j in range(i + 1, n):
		if c == k:
			flag = 1
			check = 1
			break
		if ord(a[j]) - num >= 2:
			suma += ord(a[j]) - 96
			num = ord(a[j])
			c += 1
	if suma < mina and (check == 1 or c == k):
		mina = suma
		flag = 1
	suma = 0
if flag:
	print(mina)
else:
	print(-1)


(nol, maxs) = [int(x) for x in input().split()]
ins = sorted([ord(x) for x in input()])
last = 0
ans = 0
for i in ins:
	if i - last > 1:
		ans += i - 96
		maxs -= 1
		last = i
		if maxs == 0:
			break
print([-1, ans][maxs <= 0])


(n, k) = map(int, input().split())
s = str(input())
arr = []
for i in range(n):
	if s[i] not in arr:
		arr.append(s[i])
arr.sort()
ans1 = arr[0]
ans = ord(arr[0]) - 96
z = 1
flag1 = 0
for i in range(1, len(arr)):
	if z == k:
		break
	if flag1 == 0:
		if ord(arr[i]) - ord(arr[i - 1]) > 1:
			ans1 += arr[i]
			ans += ord(arr[i]) - 96
			z += 1
			flag1 = 0
		else:
			flag1 = 1
	else:
		ans1 += arr[i]
		ans += ord(arr[i]) - 96
		z += 1
		flag1 = 0
if z == k:
	print(ans)
else:
	print(-1)


def part_weight(part_name):
	return ord(part_name) - ord('a') + 1

def can_part_be_used(part_before, part_after):
	if part_before is None:
		return True
	if ord(part_before) > ord(part_after):
		return False
	if ord(part_after) - ord(part_before) < 2:
		return False
	return True

def solve(available_parts, k):
	weight = 0
	last_part = None
	while k > 0:
		next_part = next((part for part in available_parts if can_part_be_used(last_part, part)), None)
		if next_part is None:
			print('-1')
			return
		weight += part_weight(next_part)
		available_parts.remove(next_part)
		k -= 1
		last_part = next_part
	print(weight)
(n, k) = [int(x) for x in input().split(' ')]
available_parts = sorted((char for char in input()))
solve(available_parts, k)


import string
char_val = {char: i + 1 for (i, char) in enumerate(string.ascii_lowercase)}
(n, k) = [int(x) for x in input().split(' ')]
s = input()
stages = [char_val[char] for char in s]
stages.sort()
for stage in stages:
	while stage + 1 in stages:
		stages.remove(stage + 1)
stages = sorted(list(set(stages)))
if len(stages) < k:
	ans = -1
else:
	ans = sum(stages[:k])
print(ans)


(n, k) = map(int, input().split())
s = input()
s = sorted(s)
start = ord('a')
orda = ord('a')
res = 0
cnt = 0
for i in range(n):
	if ord(s[i]) >= start and cnt < k:
		res += ord(s[i]) - orda
		start = ord(s[i]) + 2
		cnt += 1
if cnt < k:
	print(-1)
else:
	print(res + k)


def main():
	(n, k) = [int(x) for x in input().split()]
	a = list(input().strip())
	a = list(set(a))
	a.sort()
	ans = ord(a[0]) - 96
	prev = a[0]
	used = 1
	for i in range(1, len(a)):
		if ord(a[i]) > ord(prev) + 1:
			if used == k:
				break
			prev = a[i]
			ans += ord(a[i]) - 96
			used += 1
	if used < k:
		print(-1)
	else:
		print(ans)
main()


def f(s, k):
	prev_ch = -1
	w = 0
	for item in s:
		if item - 1 > prev_ch:
			w += item
			k -= 1
			prev_ch = item
		if k == 0:
			return w
	return -1
(n, k) = map(int, input().split())
s = sorted([ord(item) - ord('a') + 1 for item in set(input())])
print(f(s, k))


(n, k) = input().split()
n = int(n)
k = int(k)
s = [ord(c) - ord('a') + 1 for c in sorted(input())]
if k == 0:
	print(0)
elif s == []:
	print(-1)
else:
	(i, result, j, last) = (1, s[0], 1, 0)
	while j < k and i < len(s):
		if s[i] - s[last] > 1:
			last = i
			result += s[i]
			j += 1
		i += 1
	if j < k:
		print(-1)
	else:
		print(result)


(n, k) = list(map(int, input().strip().split(' ')))
stages = list(input())
stages.sort()
i = 1
prev = stages[0]
w = ord(prev) - 96
for s in stages[1:]:
	if i >= k:
		break
	if ord(s) - ord(prev) >= 2:
		i += 1
		w += ord(s) - 96
		prev = s
if i != k:
	print(-1)
else:
	print(w)


(n, k) = map(int, input().split())
s = input()
a = [i for i in s]
a.sort()
used = 1
prev = a[0]
res = ord(prev) - 96
i = 1
while used < k:
	if i == n:
		print(-1)
		exit(0)
	if ord(a[i]) > ord(prev) + 1:
		res += ord(a[i]) - 96
		prev = a[i]
		used += 1
	i += 1
print(res)


(n, k) = [int(i) for i in input().split()]
str = input()
lst = []
for i in str:
	lst.append(ord(i) - 96)
lst.sort()
num = 0
sum = 0
i = 0
prev = -1
while num != k and i < n:
	if lst[i] - prev > 1:
		sum += lst[i]
		num += 1
		prev = lst[i]
	i += 1
if num != k:
	print(-1)
else:
	print(sum)


(n, k) = [int(i) for i in input().split(' ')]
s = [ord(i) - 96 for i in input()]
s.sort()
ans = s[0]
cur = s[0]
l = 1
for i in range(1, n):
	if l == k:
		break
	if s[i] - cur >= 2:
		ans += s[i]
		cur = s[i]
		l += 1
if l == k:
	print(ans)
else:
	print(-1)


(n, k) = map(int, input().split())
s = [c for c in input()]
s.sort()
ans = 0
last = -1
cnt = 0
if k <= n:
	for i in range(n):
		if last == -1 or ord(s[i]) - ord(last) > 1:
			cnt += 1
			ans += ord(s[i]) - ord('a') + 1
			last = s[i]
		if cnt == k:
			break
else:
	ans = -1
if cnt < k:
	ans = -1
print(ans)


(n, k) = list(map(int, input().split()))
arr = list(map(str, input()))
arr.sort()
weight = 0
f = 0
num = 0
ind = 0
while True:
	if ind == 0:
		weight += ord(arr[ind]) + 1 - 97
		prev = arr[0]
		num += 1
		if num == k:
			break
	elif ord(arr[ind]) - ord(prev) > 1:
		weight += ord(arr[ind]) + 1 - 97
		prev = arr[ind]
		num += 1
		if num == k:
			break
	ind += 1
	if ind == n:
		f = 1
		break
if num != k:
	print(-1)
else:
	print(weight)


(n, k) = map(int, input().split())
ans = x = 0
for i in sorted(map(ord, input())):
	if i - x > 1:
		ans += i - 96
		x = i
		k -= 1
	if k == 0:
		break
if k > 0:
	print(-1)
else:
	print(ans)


(n, k) = list(map(int, input().split()))
L = []
str1 = input()
for j in str1:
	L.append(ord(j) - 96)
L = sorted(L)
stup_n = L[0]
flag = 1
rocket = L[0]
for stup in L:
	if flag < k:
		if stup - stup_n > 1:
			rocket += stup
			flag += 1
			stup_n = stup
if flag != k:
	print(-1)
else:
	print(rocket)


(n, k) = input().split()
k = int(k)
s = input()
s = ''.join(sorted(s))
a = '0'
ans = 0
for i in s:
	if ord(a) + 1 < ord(i):
		if k > 0:
			ans += ord(i) - ord('a') + 1
			a = i
			k = k - 1
if k < 1:
	print(ans)
else:
	print(-1)


(n, k) = map(int, input().split())
s = input()
s = list(s)
s.sort()
ans = 0
i = 0
l = set()
cur = None
if n == 1 and k == 1:
	print(ord(s[0]) - 96)
elif n == 1 and k > 1:
	print(-1)
else:
	while i < n and k > 0:
		cur = s[i]
		if s[i] not in l:
			ans += ord(s[i]) - 96
			l.add(s[i])
			i += 1
			k -= 1
		else:
			i += 1
		while i < n and s[i] == chr(ord(cur) + 1):
			i += 1
	if k > 0:
		print(-1)
	else:
		print(ans)


num = input()
num = num.split()
n = int(num[0])
x = int(num[1])
ip = input()
myDict = {}
ch = 'a'
for i in range(1, 27):
	myDict.update({ch: i})
	ch = chr(ord(ch) + 1)
myList = []
for c in ip:
	myList.append([c, myDict[c]])
myList.sort(key=lambda x: x[1])
sum = 0
prev = myList[0][1]
sum += prev
count = 1
done = False
if count != x:
	for i in range(1, n):
		if prev + 1 == myList[i][1] or prev == myList[i][1]:
			pass
		else:
			count += 1
			sum += myList[i][1]
			prev = myList[i][1]
			if count == x:
				done = True
				print(sum)
				break
elif count == x:
	if not done:
		print(sum)
if count != x:
	print(-1)


dic = {'@': 0, 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
(n, k) = input().split()
n = int(n)
k = int(k)
str1 = input()
l = len(str1)
li = [0 for i in range(l)]
for i in range(l):
	li[i] = str1[i]
li.sort()
fin = ['@' for i in range(k + 1)]
fin[0] = li[0]
count = 0
if count != k - 1:
	for i in range(1, l):
		if dic[li[i]] - dic[fin[count]] >= 2:
			count += 1
			fin[count] = li[i]
		if count == k - 1:
			break
sum = 0
if count != k - 1:
	print('-1')
else:
	for i in range(count + 1):
		sum = sum + dic[fin[i]]
	print(sum)


(n, k) = map(int, input().split())
s = list(input())
temp = []
while len(temp) != k and len(s) != 0:
	x = min(s)
	s.remove(x)
	if len(temp) == 0:
		temp.append(x)
	else:
		l = len(temp)
		c = ord(x) - ord(temp[l - 1])
		if c >= 2:
			temp.append(x)
if len(temp) == k:
	total = 0
	for i in temp:
		total += ord(i) - 96
	print(total)
else:
	print(-1)


(n, k) = map(int, input().split(' '))
l = [ord(c) - 96 for c in list(input())]
l.sort()
w = []
p = 0
for i in range(0, n):
	if len(w) == 0:
		w.append(l[i])
	elif l[i] - w[len(w) - 1] > 1:
		w.append(l[i])
	if len(w) == k:
		p = 1
		break
if p == 0:
	print(-1)
else:
	print(sum(w))


(n, k) = [int(i) for i in input().split()]
s = [i for i in input()]
s.sort()
mass = 0
last = -2
for i in range(n):
	if ord(s[i]) - ord('a') - 2 >= last:
		mass += ord(s[i]) - ord('a') + 1
		k -= 1
		last = ord(s[i]) - ord('a')
	if k <= 0:
		break
if k > 0:
	print(-1)
else:
	print(mass)


(n, k) = [int(a) for a in input().split()]
data = sorted(list(input()))
num = 1
a = 0
result = ord(data[0]) - 96
if k == 1:
	print(result)
else:
	for i in range(1, n):
		if ord(data[i]) - ord(data[a]) > 1:
			num += 1
			result += ord(data[i]) - 96
			a = i
		if num == k:
			break
	if num >= k:
		print(result)
	else:
		print(-1)


L = [int(i) for i in input().strip().split()]
n = L[0]
k = L[1]
str = input()
c = [ord(i) - 96 for i in str]
count = 0
p = -1
count2 = 0
flag = 0
while True:
	if c == []:
		flag = 1
		break
	x = min(c)
	c.remove(x)
	if x <= p + 1:
		continue
	count2 += 1
	count += x
	if count2 == k:
		break
	p = x
if flag != 1:
	print(count)
else:
	print(-1)


(n, k) = map(int, input().split())
s = sorted(list(input()))
prev = 0
w = 0
for el in s:
	if k == 0:
		break
	if ord(el) >= prev + 2:
		k -= 1
		w += ord(el) - ord('a') + 1
		prev = ord(el)
if k == 0:
	print(w)
else:
	print(-1)


(n, k) = [int(i) for i in input().split()]
s = sorted(input())
(summa, i, z) = (ord(s[0]) - 97 + 1, 1, s[0])
while i < n:
	if k <= 1:
		break
	if ord(s[i]) - 97 + 1 - (ord(z) - 97 + 1) >= 2:
		summa += ord(s[i]) - 97 + 1
		(z, k) = (s[i], k - 1)
	i += 1
print(summa if k <= 1 else -1)


na = list(map(int, input().split()))
s = input()
n = na[0]
k = na[1]
amk = 0
s = sorted(s)
last = -2
ans = 0
amdone = 0
for i in range(len(s)):
	if amdone == k:
		break
	if k + amk > n:
		print(-1)
		return
	if ord(s[i]) - 96 > last + 1:
		last = ord(s[i]) - 96
		ans += ord(s[i]) - 96
		amdone += 1
	else:
		amk += 1
if k + amk > n:
	print(-1)
else:
	print(ans)


(n, k) = input().split()
n = int(n)
k = int(k)
inputed = list(input())
inputed.sort()
out = [inputed[0]]
i = 0

def SumOfAscii(a):
	x = 0
	for j in range(len(a)):
		x += ord(a[j]) - 96
	return x
while len(out) != k and len(out) <= n:
	try:
		i += 1
		if ord(inputed[i]) > ord(out[len(out) - 1]) + 1:
			out.append(inputed[i])
	except IndexError:
		print(-1)
		exit()
print(SumOfAscii(out))


a = [int(x) for x in input().split()]
b = input()
lst = []
for i in range(a[0]):
	lst.append(ord(b[i]) - 96)
c = sorted(lst)
ans = [c[0]]
i = 1
j = 0
while i < a[0]:
	if c[i] - c[j] > 1:
		ans.append(c[i])
		j = i
		i = i + 1
	else:
		i += 1
if len(ans) < a[1]:
	p = -1
else:
	p = sum(ans[0:a[1]])
print(p)


(n, k) = map(int, input().split())
s = sorted(map(ord, input()))
r = s[:1]
for c in s[1:]:
	if c > r[-1] + 1:
		r.append(c)
print(-1 if len(r) < k else sum(r[:k]) - 96 * k)


(n, k) = map(int, input().split())
s = list(input())
s.sort()
l = [s[0]]
x = s[0]
for i in range(1, n):
	if len(l) == k:
		break
	if ord(s[i]) - ord(x) > 1:
		l.append(s[i])
		x = s[i]
if len(l) != k:
	print(-1)
else:
	q = 0
	for i in range(k):
		q = q + (ord(l[i]) - 96)
	print(q)


(n, k) = map(int, input().split())
s = input()
s = ''.join(sorted(s))
wynik = s[0]
index = 1
while index < n:
	if ord(s[index]) - ord(wynik[-1]) >= 2:
		wynik += s[index]
	index += 1
if len(wynik) < k:
	print(-1)
	exit()
suma = 0
for i in range(k):
	suma += ord(wynik[i]) - 96
print(suma)


a = input().split()
n = int(a[0])
k = int(a[1])
s = input()
s = sorted(s)
news = []
for i in range(n):
	if len(news) == k:
		break
	if len(news) == 0:
		news.append(ord(s[i]))
	elif ord(s[i]) - news[-1] > 1:
		news.append(ord(s[i]))
if len(news) == k:
	print(sum(news) - 96 * k)
else:
	print(-1)


(n, k) = map(int, input().split())
a = list(input())
a.sort()
c = ord('a') - 1
a = [ord(elem) - c for elem in a]
cur = -1
ans = 0
for i in range(n):
	if k == 0:
		break
	if a[i] > cur + 1:
		cur = a[i]
		ans += a[i]
		k -= 1
if k > 0:
	print(-1)
else:
	print(ans)


(a, b) = map(int, input().split())
c = input()
sorted(c)
summa = 0
count = 0
j = -2
i = 0
abc = 'abcdefghijklmnopqrstuvwxyz'
while i < 26 and count < b:
	if abc[i] in c and i - 2 >= j:
		summa += i + 1
		count += 1
		j = i
	i += 1
if count < b:
	print(-1)
else:
	print(summa)


(n, k) = map(int, input().split())
s = list(input())
s.sort()
ans = 0
used = 0
pos = 0
for i in range(n):
	if used == k:
		break
	if i == 0:
		ans += ord(s[i]) - 96
		used += 1
		pos = 0
	elif ord(s[i]) - ord(s[pos]) > 1:
		ans += ord(s[i]) - 96
		pos = i
		used += 1
if used < k:
	print(-1)
else:
	print(ans)


(n, k) = map(int, input().split())
s = list(input())
s.sort()
c = 0
ka = 0
l = ord('a') - 2
for i in range(n):
	if ord(s[i]) >= l + 2:
		c = c + 1
		l = ord(s[i])
		ka = ka + (ord(s[i]) - 96)
	if c == k:
		break
if c == k:
	print(ka)
else:
	print(-1)


(n, k) = [int(i) for i in input().split()]
s = str(input())
s = sorted(s)
if k == 1:
	print(ord(s[0]) - 96)
else:
	t = ord(s[0])
	sum = t - 96
	k = k - 1
	for i in range(1, n):
		if ord(s[i]) - t >= 2 and k > 0:
			k = k - 1
			t = ord(s[i])
			sum = sum + (ord(s[i]) - 96)
		if k == 0:
			print(sum)
			break
	if k != 0:
		print(-1)


from sys import stdin
(n, k) = [int(i) for i in stdin.readline().split(' ')]
trim = lambda s: s[:-1] if s[-1] == '\n' else s
stages = ''.join(sorted(trim(stdin.readline())))
weight = 0
j = 0
lastStage = '_'
for i in range(0, k):
	while j < n and ord(stages[j]) <= ord(lastStage) + 1:
		j += 1
	if j >= n:
		weight = -1
		break
	lastStage = stages[j]
	weight += ord(stages[j]) - 96
print(weight)


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
(n, k) = map(int, sys.stdin.readline().split(' '))
ss = str(input())
s = ''.join(sorted(ss))
ans = []
ans.append(s[0])
prev = 0
for i in range(1, n):
	if ord(s[i]) - ord(ans[prev]) >= 2:
		ans.append(s[i])
		prev += 1
if len(ans) < k:
	print(-1)
else:
	val = 0
	for i in range(k):
		val += ord(ans[i]) - ord('a') + 1
	print(val)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


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

def tonny(i):
	return ord(i) - 96
a = sorted(input())
a = list(map(tonny, a))
a = sorted(list(set(a)))
ans = [a.pop(0)]
k -= 1
for j in a:
	if j - ans[-1] > 1 and k > 0:
		k -= 1
		ans.append(j)
	if k == 0:
		break
if k != 0:
	print(-1)
else:
	print(sum(ans))


(n, m) = map(int, input().strip().split())
r = input()
e = list(r)
e.sort()

def find(s):
	r1 = 'abcdefghijklmnopqrstuvwxyz'
	for i in range(26):
		if s == r1[i]:
			return i + 1
ans = find(e[0])
count = 1
prev = e[0]
for i in range(1, n):
	if count == m:
		print(ans)
		exit(0)
	if find(e[i]) - find(prev) > 1:
		prev = e[i]
		ans = ans + find(e[i])
		count = count + 1
if count == m:
	print(ans)
	exit(0)
print(-1)


(n, k) = map(int, input().split())
s = set(str(input()))
if k > 13 or k > len(s):
	print(-1)
else:
	l = sorted(s)
	m = ord(l[0]) - 96
	q = m
	c = 1
	for e in l[1:]:
		if k > c:
			a = ord(e) - 96
			if a - m != 1:
				m = a
				c += 1
				q += a
			elif n == k:
				q = -1
				break
		else:
			break
	print(q)


import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

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

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

def string_list():
	return list(input())
(n, k) = num_input()
s = list(input())
s.sort()
cost = ord(s[0]) - ord('a') + 1
prev = s[0]
k -= 1
for i in range(1, n):
	if k == 0:
		break
	if ord(s[i]) - ord(prev) > 1:
		cost += ord(s[i]) - ord('a') + 1
		prev = s[i]
		k -= 1
if k == 0:
	print(cost)
else:
	print(-1)


(n, k) = map(int, input().split())
s = list(input())
s.sort()
if k == 1:
	print(ord(s[0]) - 96)
	quit()
r = []
count = 1
r.append(s[0])
lastadd = s[0]
for i in range(1, n):
	if ord(s[i]) - ord(lastadd) > 1 and count < k:
		r.append(s[i])
		lastadd = s[i]
		count += 1
if count < k:
	print(-1)
	quit()
count = 0
for i in r:
	count += ord(i) - 96
print(count)


(n, k) = map(int, input().split())
a = sorted(list(map(lambda x: ord(x) - 96, list(input()))))
b = [a[0]]
a = a[1:]
for i in a:
	if i - b[-1] > 1:
		b.append(i)
if len(b) >= k:
	print(sum(b[:k]))
else:
	print(-1)


def main():
	[_, k] = map(int, input().split(' '))
	letters = list(set([ord(x) - 96 for x in list(input())]))
	a = check(letters, k)
	if a > 9000:
		print(-1)
	else:
		print(a)

def check(letters, k):
	if k == 0:
		return 0
	elif len(letters) == 0:
		return 9001
	else:
		letters2 = letters
		m = min(letters2)
		letters2.remove(m)
		if m + 1 in letters2:
			letters2.remove(m + 1)
		return m + check(letters2, k - 1)
main()


(n, k) = map(int, input().split())
s = input()
list = []
for sym in s:
	list.append(sym)
list.sort()
last = list[0]
ans = ord(last) - ord('a') + 1
k -= 1
if k == 0:
	print(ans)
	exit(0)
for sym in list:
	if ord(sym) - ord(last) > 1:
		last = sym
		k -= 1
		ans += ord(sym) - ord('a') + 1
		if k == 0:
			print(ans)
			exit(0)
print(-1)


(n, k) = map(int, input().split())
alpha = 'abcdefghijklmnopqrstuvwxyz'
ch = str(input())
L = list(ch)
L.sort()
i = 1
d = {}
for x in alpha:
	d[x] = i
	i += 1
s = L[0]
m = d[L[0]]
l = 1
while len(s) < k and l <= n - 1:
	if d[L[l]] - d[s[-1]] >= 2:
		s = s + L[l]
		m += d[L[l]]
	l += 1
if len(s) < k:
	print(-1)
else:
	print(m)


from collections import defaultdict
(n, k) = map(int, input().split())
s = input()
deft = defaultdict(int)
ss = set(s)
for v in ss:
	deft[ord(v) - ord('a') + 1] += 1
ans = 0
b = set()
for i in range(1, 27):
	if not k:
		break
	if deft[i] and (not i - 1 in b):
		k -= 1
		ans += i
		b.add(i)
if k:
	print(-1)
else:
	print(ans)


(n, k) = map(int, input().split())
s = sorted(list(set(input())))
s1 = 'abcdefghijklmnopqrstuvwxyz'
(z, c) = (s[0], 1)
for i in range(1, len(s)):
	if c == k:
		break
	if s1.index(s[i]) == s1.index(z[-1]) + 1:
		continue
	z += s[i]
	c += 1
if c < k:
	print('-1')
	exit()
v = 0
for i in z:
	v += s1.index(i) + 1
print(v)


(n, k) = map(int, input().split())
s = [ord(c) - 96 for c in list(input())]
s.sort()
i = 1
ans = s[0]
c = 1
last = s[0]
while i < n and c < k:
	if s[i] - last > 1:
		ans += s[i]
		last = s[i]
		c += 1
	i += 1
	if c == k:
		break
print(-1 if c < k else ans)


from string import ascii_lowercase
alfabeto = ascii_lowercase
(n, k) = input().split()
(n, k) = (int(n), int(k))
word = input().strip()
counter = 0
total = 0
i = 0
while i < len(alfabeto):
	if total == k:
		break
	if alfabeto[i] in word:
		total += 1
		counter += i + 1
		i += 1
	i += 1
if total != k:
	print('-1')
else:
	print(counter)


(n, k) = map(int, input().split())
stri = input()
a = [0] * 26
for i in range(len(stri)):
	x = ord(stri[i]) - ord('a')
	a[x] += 1
wt = 0
count = 0
i = 0
while i < 26 and count < k:
	if a[i] >= 1:
		count += 1
		wt += i + 1
		i += 2
	else:
		i += 1
if count == k:
	print(wt)
else:
	print('-1')


(n, k) = [int(x) for x in input().split()]
s = {x for x in input()}
s = list(s)
s.sort()
wt = 0
c = 0
last = ' '
for i in s:
	if last == chr(ord(i) - 1):
		continue
	wt = wt + (ord(i) - 96)
	c += 1
	if c == k:
		break
	last = i
if c < k:
	print(-1)
else:
	print(wt)


l = 'abcdefghijklmnopqrstuvwxyz'
dicti = {}
for g in range(0, 26):
	dicti[l[g]] = g + 1
(n, k) = map(int, input().split())
string = input()
l1 = []
for val in range(len(string)):
	l1.append(string[val])
l1.sort()
sump = dicti[l1[0]]
t = 0
w = 1
s = 1
gk = 0
if k == 1:
	print(sump)
else:
	while s < len(l1) and gk < len(l1):
		if dicti[l1[s]] - dicti[l1[gk]] >= 2:
			w += 1
			gk = s
			s += 1
			sump += dicti[l1[s - 1]]
			if w == k:
				t = 1
				break
		elif w == k:
			t = 1
			break
		else:
			s += 1
	if t == 1:
		print(sump)
	else:
		print(-1)


(n, m) = map(int, input().split())
s = sorted(input())
out = []
for i in range(n):
	if len(out) < 1:
		out.append(s[i])
	elif ord(s[i]) > ord(out[-1]) + 1:
		out.append(s[i])
if m > len(out):
	print(-1)
	exit()
add = 0
for i in range(m):
	add += ord(out[i]) - 96
print(add)


import math
import fractions
t = list(map(int, input().split()))
k = t[1]
s = list(set(input()))
s.sort()
alpha = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
s_len = len(s)
count = 0
val = -1
weight = 0
prev = '-1'
for i in range(s_len):
	if i == 0:
		weight = weight + alpha[s[i]]
		prev = s[i]
		count = count + 1
	elif alpha[s[i]] - alpha[prev] > 1:
		weight = weight + alpha[s[i]]
		prev = s[i]
		count = count + 1
	if count == k:
		val = 0
		break
if val == 0:
	print(weight)
else:
	print(-1)


(n, k) = list(map(int, input().split()))
s = input()
weights = sorted(set((ord(i) - ord('a') + 1 for i in s)))
last_used = weights[0]
min_weigth = k * 26
used = 1
current_weight = last_used
index = 1
while index < len(weights) and used < k:
	weight = weights[index]
	if weight > last_used + 1:
		current_weight += weight
		used += 1
		last_used = weight
	index += 1
if used < k:
	print(-1)
else:
	print(current_weight)


from collections import Set
param = input().split()
stages = input()
stage_set = set()
for char in stages:
	if char not in stage_set:
		stage_set.add(char)
stage_li = []
alphabet = 'abcdefghijklmnopqrstuvwxyz'
counter = 0
while len(stage_li) < int(param[1]) and counter < 26:
	if alphabet[counter] in stage_set:
		stage_li.append(alphabet[counter])
		counter += 2
	else:
		counter += 1
if len(stage_li) < int(param[1]):
	print(-1)
else:
	sum = 0
	for stage in stage_li:
		sum += alphabet.find(stage) + 1
	print(sum)


(n, k) = map(int, input().split())
s = input()
ans = 0
pre = -2
for x in range(26):
	if chr(ord('a') + x) in s and x - pre >= 2:
		ans += x + 1
		pre = x
		k -= 1
		if k is 0:
			break
print(-1 if k > 0 else ans)


a = [int(q) for q in input().strip().split()]
b = list(input())
b.sort()
sum = 0
ct = 0
t = 0
for k in range(a[0]):
	if a[1] == 1:
		break
	if k == 0:
		t = ord(b[k])
		sum += ord(b[k]) - 96
	elif ord(b[k]) - t >= 2:
		sum += ord(b[k]) - 96
		t = ord(b[k])
		ct += 1
		if ct == a[1] - 1:
			break
if a[1] == 1:
	print(ord(b[0]) - 96)
elif ct < a[1] - 1:
	print(-1)
else:
	print(sum)


def stages():
	(n, k) = map(int, input().split())
	s = sorted(list(set(input())))
	s = [ord(c) - 96 for c in s]
	if len(s) < k:
		return -1
	if len(s) == 1 and k == 1:
		return s[0]
	results = set()
	for i in range(len(s) - 1):
		curr = s[i]
		weight = [curr]
		for j in range(i + 1, len(s)):
			if s[j] - curr >= 2:
				weight.append(s[j])
				curr = s[j]
		if len(weight) == k:
			results.add(sum(weight))
		elif len(weight) > k:
			for i in range(0, len(weight), k):
				if len(weight[i:i + k]) == k:
					results.add(sum(weight[i:i + k]))
	if len(results) == 0:
		return -1
	return min(results)
print(stages())


(n, m) = map(int, input().split())
s = input()
s = list(map(lambda x: ord(x), s))
s.sort()
sum1 = 0
curr = -2
c = 0
flag = 0
for alp in s:
	if alp - curr > 1:
		c += 1
		sum1 += alp - 96
		curr = alp
	if c >= m:
		flag = 1
		break
if flag == 0:
	print(-1)
else:
	print(sum1)


(n, k) = map(int, input().split())
s = [ord(x) - ord('a') + 1 for x in sorted(set(input()))]
stages = []
prev = -1
for x in s:
	if x - prev >= 2:
		stages.append(x)
		prev = x
if len(stages) < k:
	print(-1)
else:
	print(sum(stages[:k]))


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

def f(x):
	return ord(x) - ord('a') + 1
a = []
for i in s:
	a.append(i)
a.sort()
curr = 1
count = 1
ans = 0
last = 0
ans += f(a[0])
while curr < n and count < k:
	if f(a[curr]) - f(a[last]) >= 2:
		ans += f(a[curr])
		last = curr
		count += 1
	curr += 1
if count == k:
	print(ans)
else:
	print(-1)


(n, k) = list(map(int, input().split()))
a = input()
res = [0] * 26
cnt = 0
f = 0
ans = 0
for i in range(n):
	res[ord(a[i]) - ord('a')] = 1
for u in range(26):
	if res[u] == 1 and f == 0:
		cnt += 1
		f = 1
		ans += u + 1
		if cnt == k:
			break
	else:
		f = 0
if cnt < k:
	print(-1)
else:
	print(ans)


X = list(map(int, input().split()))
Stages = sorted(set(input()))
if X[1] == 1:
	print(ord(Stages[0]) - 96)
	exit()
for i in range(0, len(Stages) - X[1] + 1):
	Answer = list()
	Answer.append(Stages[i])
	for j in range(i + 1, len(Stages)):
		if ord(Stages[j]) - ord(Answer[-1]) > 1:
			Answer.append(Stages[j])
			if len(Answer) == X[1]:
				print(sum([ord(c) - 96 for c in Answer]))
				exit()
print(-1)


(n, m) = map(int, input().split())
z = list(input())
l = []
for i in z:
	l.append(ord(i) - 96)
l.sort()
sumi = l[0]
last = l[0]
i = 1
while m - 1 > 0 and i < n:
	if l[i] > last + 1:
		sumi = sumi + l[i]
		last = l[i]
		m = m - 1
	i = i + 1
if m - 1 > 0:
	print(-1)
else:
	print(sumi)


(n, k) = map(int, input().split())
l = list(input())
l.sort()
(ans, d) = (ord(l[0]) - 96, 0)
(i, j) = (0, 0)
while i < n:
	if abs(ord(l[i]) - ord(l[j])) >= 2:
		ans += int(ord(l[i])) - 96
		j = i
		d += 1
	if d == k - 1:
		print(ans)
		exit()
	i += 1
print(-1)


d = [False for i in range(26)]
(n, k) = map(int, input().split())
for el in str(input()):
	d[ord(el) - ord('a')] = True
ans = 100000000000000

def get_ans(i):
	if not d[i]:
		return 100000000000000
	last = i + 2
	ret = i + 1
	gett = 1
	for j in range(i + 2, 26):
		if j >= last and d[j] and (gett < k):
			last = j + 2
			ret += j + 1
			gett += 1
	if gett != k:
		return 100000000000000
	return ret
for i in range(26):
	ans = min(ans, get_ans(i))
print(-1 if ans == 100000000000000 else ans)


(n, k) = list(map(int, input().split()))
s = list(map(str, input()))
a = list(sorted(s))
j = 0
o = 0
lir = 0
if k == 1:
	print(ord(a[0]) - 96)
else:
	for i in range(1, len(a)):
		if i == 1:
			lir += ord(a[0]) - 96
			k -= 1
		if ord(a[i]) - ord(a[j]) > 1:
			lir += ord(a[i]) - 96
			j = i
			k -= 1
		if k == 0:
			break
	if k > 0:
		print(-1)
	else:
		print(lir)


(n, k) = map(int, input().split())
s = input()
a = []
for i in s:
	a.append(ord(i) - ord('a') + 1)
a.sort()
ans = a[0]
t = 1
final = a[0]
for i in range(1, n):
	if t >= k:
		break
	if a[i] - final > 1:
		ans += a[i]
		final = a[i]
		t += 1
if t != k or k > n:
	print('-1')
else:
	print(ans)


(n, k) = map(int, input().split())
s = list(input())
s.sort()
keka = ord(s[0])
j = 1
cnt = ord(s[0]) - 96
for i in range(1, n):
	if j < k and ord(s[i]) - keka >= 2:
		j += 1
		keka = ord(s[i])
		cnt += ord(s[i]) - 96
if j == k:
	print(cnt)
else:
	print(-1)


(n, k) = map(int, input().split())
s = input()
l = []
s = sorted(s)
for i in range(n):
	if len(l) >= k:
		break
	if len(l) == 0:
		l.append(s[i])
	elif ord(s[i]) - ord(l[-1]) > 1:
		l.append(s[i])
if len(l) == k:
	p = 0
	for i in range(k):
		p += ord(l[i]) - 97 + 1
	print(p)
else:
	print(-1)


Input = lambda : map(int, input().split())
(n, k) = Input()
s = sorted(input())
t = s[0]
value = ord(t) - 96
c = 1
for i in range(1, n):
	if c == k:
		break
	if ord(s[i]) - ord(t) > 1:
		t = s[i]
		value += ord(t) - 96
		c += 1
if c == k:
	print(value)
else:
	print(-1)


(n, k) = list(map(int, input().split()))
s = sorted(input())
(su, i, e) = (ord(s[0]) - 96, 1, s[0])
while i < n:
	if k <= 1:
		break
	if ord(s[i]) - 96 - (ord(e) - 96) >= 2:
		su += ord(s[i]) - 96
		(e, k) = (s[i], k - 1)
	i += 1
print(su if k <= 1 else -1)


(n, k) = map(int, input().split())
s = input()
s = sorted(s)
c = k - 1
s1 = s[0]
l = 0
for i in range(1, n):
	if ord(s[i]) - ord(s1[l]) > 1 and c != 0:
		c -= 1
		s1 += s[i]
		l += 1
	if c == 0:
		break
if c == 0:
	a = 0
	for k in s1:
		a += ord(k) - ord('a') + 1
	print(a)
else:
	print(-1)


(n, k) = map(int, input().split())
s = input()
f = [0] * 26
for c in s:
	f[ord(c) - 97] += 1
skip = 0
ans = 0
for i in range(26):
	if skip:
		skip ^= 1
		continue
	elif f[i]:
		skip ^= 1
		ans += i + 1
		k -= 1
	else:
		pass
	if not k:
		break
print(-1 if k else ans)


def main():
	(n, k) = map(int, input().split())
	s = input()
	s = ''.join(sorted(s))
	ans = []
	for c in s:
		curr = ord(c) - ord('a') + 1
		if len(ans) == 0:
			ans.append(curr)
		elif len(ans) < k and len(ans) > 0 and (curr > ans[len(ans) - 1] + 1):
			ans.append(curr)
		elif len(ans) >= k:
			break
	print(sum(ans) if len(ans) == k else -1)
main()


import sys
(n, k) = map(int, input().split())
s = list(input())
s.sort()
last = ord('a') - 2
ln = 0
ans = 0
for i in range(n):
	if ord(s[i]) >= last + 2:
		last = ord(s[i])
		ans += last - 96
		ln += 1
		if ln == k:
			break
if ln == k:
	print(ans)
else:
	print(-1)


(n, k) = map(int, input().split())
s = input()
d = [False] * 26
for c in s:
	d[ord(c) - ord('a')] = True
w = 0
l = 0
i = 0
while i < 26 and l < k:
	if d[i]:
		w += i + 1
		l += 1
		i += 2
	else:
		i += 1
if l == k:
	print(w)
else:
	print(-1)


(n, k) = map(int, input().split())
s = sorted(input())
ans = ord(s[0]) - 96
check = s[0]
k -= 1
for i in range(1, n):
	if k == 0:
		break
	if ord(s[i]) - ord(check) > 1:
		k -= 1
		ans += ord(s[i]) - 96
		check = s[i]
print('-1' if k > 0 else ans)


mod = 10 ** 9 + 7
import math
for _ in range(1):
	(n, m) = map(int, input().split())
	s = input()
	arr = [0 for i in range(26)]
	for i in s:
		arr[ord(i) - 97] = 1
	i = 0
	ans = 0
	while i < 26 and m > 0:
		if arr[i] == 1:
			ans += i + 1
			i += 1
			m -= 1
		i += 1
	if m == 0:
		print(ans)
	else:
		print(-1)


tk = list(map(int, input().split()))
t = tk[0]
k = tk[1]
s = list(input())
s.sort()
g = [s[0]]
flag = s[0]
for i in range(1, t):
	if ord(s[i]) - ord(flag) > 1:
		g.append(s[i])
		flag = s[i]
summ = 0
if len(g) >= k:
	for i in range(k):
		summ += ord(g[i]) - 96
	print(summ)
else:
	print('-1')


(n, k) = map(int, input().split())
s = list(map(ord, sorted(input())))
last = 0
total = 0
i = 0
while i < n:
	if s[i] > last + 1:
		total += s[i] - 96
		last = s[i]
		k -= 1
		if k == 0:
			break
	i += 1
if i < n:
	print(total)
else:
	print(-1)


(n, m) = map(int, input().split())
alph = ['1', '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()
a = []
for i in s:
	a.append(i)
a.sort()
s = a[0]
answ = alph.index(a[0])
if m != 1:
	for i in range(1, n):
		if len(s) == m:
			break
		if a[i] not in s and alph.index(a[i]) - alph.index(s[len(s) - 1]) > 1:
			answ += alph.index(a[i])
			s += a[i]
	if answ != alph.index(a[0]) and len(s) == m:
		print(answ)
	else:
		print(-1)
else:
	print(alph.index(a[0]))


(n, k) = map(int, input().split())
s = input()
N = [False] * 26
for i in range(n):
	N[ord(s[i]) - 97] = True
c = 0
w = 0
i = 0
while i < 26:
	if N[i]:
		c += 1
		w += i + 1
		i += 1
	i += 1
	if c == k:
		break
if c == k:
	print(w)
else:
	print(-1)


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(n, k) = I()
s = input()
s = sorted(s)

def get(x):
	return ord(x) - 97 + 1
ans = get(s[0])
previous = get(s[0])
if k == 1:
	print(ans)
	exit()
count = 1
for i in range(1, n):
	if get(s[i]) - previous >= 2:
		previous = get(s[i])
		ans += previous
		count += 1
	if count == k:
		print(ans)
		break
else:
	print(-1)


temp = input()
(n, max_weights) = temp.split(' ')
(n, max_weights) = (int(n), int(max_weights))
weights = input()
weights = ''.join(sorted(weights))
prev = 'A'
total = 0
res = 0
result = []
ok = False
for w in weights:
	if ord(w) - 1 == ord(prev) or total >= max_weights or w in result:
		pass
	else:
		prev = w
		total += 1
		result.append(w)
		res += ord(w) - 96
		ok = True
if len(result) != max_weights:
	print(-1)
else:
	print(res)


(n, leng) = list(map(int, input().split()))
s = input()
l = [0] * 27
for c in s:
	l[ord(c) - ord('a') + 1] += 1
i = 0
num = 0
out = 0
while i < 27 and num < leng:
	if l[i]:
		out += i
		i += 2
		num += 1
	else:
		i += 1
if num == leng:
	print(out)
else:
	print(-1)


(n, k) = list(map(int, input().split()))
a = sorted(input())
(temp, count) = (-1, 0)
for i in range(n):
	if k == 0:
		break
	if ord(a[i]) >= temp + 2:
		count += ord(a[i]) - 97 + 1
		temp = ord(a[i])
		k -= 1
if k == 0:
	print(count)
else:
	print(-1)


(n, k) = map(int, input().split())
a = list(set(input()))
a.sort()
ans = 0
prev = -10
jap = 0
for i in a:
	if ord(i) - prev > 1:
		ans += ord(i) - 96
		prev = ord(i)
		jap += 1
	if jap == k:
		break
if k == jap:
	print(ans)
else:
	print(-1)


(n, k) = [int(c) for c in input().split(' ')]
line = [c for c in input()]
line.sort()
alphabet = 'abcdefghijklmnopqrstuvwxyz'
alphabet_weight = {}
for i in range(len(alphabet)):
	alphabet_weight[alphabet[i]] = i + 1
s = 0
p = 0
i = 0
previous_weight = -10000
while i < n:
	if alphabet_weight[line[i]] > previous_weight + 1:
		s += alphabet_weight[line[i]]
		previous_weight = alphabet_weight[line[i]]
		p += 1
	if p == k:
		break
	i += 1
if i == n:
	s = -1
print(s)


(n, k) = map(int, input().split())
arr = sorted(list(input().strip()))
curr = 0
ans = [ord(arr[0]) - ord('a')]
for i in arr:
	if ord(i) - ord('a') - ans[len(ans) - 1] >= 2:
		ans.append(ord(i) - ord('a'))
if len(ans) < k:
	print(-1)
else:
	print(sum(ans[:k]) + k)


def map_stages_avaiability(stages, alphabet, stages_avaiability):
	for used_stage in stages:
		for (letter_idx, stage_letter) in enumerate(alphabet):
			if used_stage == stage_letter:
				stages_avaiability[letter_idx] += 1
				break
question = input().split()
stages = input()
stages_limit = int(question[1])
alphabet = 'abcdefghijklmnopqrstuvwxyz'
stage_blocker = -1
stages_avaiability = [0] * 26
map_stages_avaiability(stages, alphabet, stages_avaiability)
weigth = 0
stages_used = 0
for (stage_idx, stage) in enumerate(stages_avaiability):
	if stages_limit == stages_used:
		break
	if stage > 0 and stage_blocker < stage_idx:
		weigth += stage_idx + 1
		stage_blocker = stage_idx + 1
		stages_used += 1
if weigth == 0 or stages_used < stages_limit:
	weigth = -1
print(weigth)


l = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
(n, k) = map(int, input().split())
s = ''.join(sorted(input()))
ans = []
f = 0
ans.append(s[0])
c = l[s[0]]
if len(ans) == k:
	print(c)
	exit(0)
for i in range(1, n):
	if l[s[i]] > l[ans[-1]] + 1:
		ans.append(s[i])
		c += l[s[i]]
	if len(ans) == k:
		f = 1
		break
if f:
	print(c)
else:
	print(-1)


cache = input().split()
n = int(cache[0])
k = int(cache[1])
step = list(input())
step = list(set(step))
step.sort()
stepInt = []
min = ord(step[0]) - 96
res = min
count = 1
if count != k:
	for i in range(1, len(step)):
		x = ord(step[i]) - 96
		if x - min > 1:
			min = x
			res += min
			count += 1
		if count == k:
			break
if count != k:
	print('-1')
else:
	print(res)


(n, k) = [int(x) for x in input().split()]
st = input()
st = sorted(st)
fin = []
size = -1
i = -1
for j in range(n):
	if i == -1:
		fin.append(st[j])
		i += 1
	elif ord(st[j]) - ord(fin[i]) not in range(-1, 2):
		fin.append(st[j])
		i += 1
	if i == k - 1:
		size = 0
		for w in range(k):
			size += ord(fin[w]) - 96
		break
print(size)


def f(x):
	al = 'abcdefghijklmnopqrstuvwxyz'
	return al.index(x) + 1
(n, k) = map(int, input().split())
s = input()
a = [0] * n
for i in range(n):
	a[i] = f(s[i])
a.sort()
ans = a[0]
p = 0
cnt = 1
for i in range(1, n):
	if a[i] - a[p] > 1 and cnt < k:
		cnt += 1
		ans += a[i]
		p = i
if not cnt == k:
	ans = -1
print(ans)


(n, k) = map(int, input().split())
li = list(input())
l = list(set(li))
l.sort()
test = list('abcdefghijklmnopqrstuvwxyz')
pos = test.index(l[0])
lp = [l[0]]
for i in range(len(l)):
	if test.index(l[i]) - pos > 1:
		lp.append(l[i])
		pos = test.index(l[i])
	if len(lp) == k:
		break
if len(lp) < k:
	print(-1)
else:
	co = 0
	for i in lp:
		co += test.index(i) + 1
	print(co)


(n, k) = map(int, input().split())
s = input()
dp = [0] * 26
for i in s:
	dp[ord(i) - 97] = 1
	ans = 0
	c = -2
	ct = 0
	tf = False
	for i in range(len(dp)):
		if i - c >= 2 and dp[i] == 1:
			c = i
			ans += i + 1
			ct += 1
		if ct == k:
			tf = True
			break
if tf:
	print(ans)
else:
	print(-1)


(a, b) = [int(i) for i in input().split()]
mystr = input()
strarr = [ord(i) - 96 for i in sorted(mystr)]
minv = 50 * 26
for i in range(a):
	count = 1
	current = i
	c = [strarr[i]]
	for o in range(i + 1, a):
		if strarr[o] - strarr[current] >= 2:
			count += 1
			current = o
			c.append(strarr[current])
	if count >= b:
		if sum(c[:b]) < minv:
			minv = sum(c[:b])
if minv == 50 * 26:
	print(-1)
else:
	print(minv)


(n, k) = map(int, input().split())
a = input()
s = list(a)
s.sort()
x = ord(s[0]) - ord('a') + 1
w = x
y = 1
for i in range(n - 1):
	if ord(s[i + 1]) - ord('a') + 1 - x >= 2 and y <= k - 1:
		x = ord(s[i + 1]) - ord('a') + 1
		w += x
		y += 1
if y == k:
	print(w)
else:
	print(-1)


import sys
char_map = dict([(i, 0) for i in range(1, 27)])

def main():
	line = sys.stdin.readline()
	numbers = [int(s) for s in line.split() if s.isdigit()]
	stage_number = numbers[0]
	needled_stages = numbers[1]
	available_stages = sys.stdin.readline().replace('\n', '')
	for c in available_stages:
		char_map[ord(c) - ord('a') + 1] += 1
	weight = 0
	key = 1
	used = 0
	while key <= 26 and used < needled_stages:
		if char_map[key] > 0:
			weight += key
			key += 1
			used += 1
		key += 1
	if weight == 0 or used < needled_stages:
		sys.stdout.write('-1')
	else:
		sys.stdout.write(str(weight))
main()


(k, n) = input().split()
(k, n) = (int(k), int(n))
string = sorted(list(input()))
stages = 0
sum = 0
pos = -1
for i in range(k):
	alphPos = ord(string[i]) - 96
	if pos + 1 < alphPos:
		sum += alphPos
		pos = alphPos
		stages += 1
		if stages == n:
			print(sum)
			break
if stages < n:
	print(-1)


(n, k) = [int(x) for x in input().split(' ')]
s = sorted(set(input()))
all = [ord(ch) - ord('a') + 1 for ch in s]
last = all[0]
cost = all[0]
taken = 1
for i in range(1, len(all)):
	if all[i] - last >= 2 and taken < k:
		cost += all[i]
		last = all[i]
		taken += 1
if taken == k:
	print(cost)
else:
	print(-1)


(n, k) = map(int, input().split())
s = input()
alph = 'abcdefghijklmnopqrstuvwxyz'
s = sorted(s)
min_count = float('inf')
for i in range(n):
	c = 1
	j = 0
	count = alph.find(s[i]) + 1
	x = alph.find(s[i])
	while c != k and j != n:
		if i != j and alph.find(s[j]) > x + 1:
			c += 1
			count += alph.find(s[j]) + 1
			x = alph.find(s[j])
		j += 1
	if c == k and count < min_count:
		min_count = count
print(-1 if min_count == float('inf') else min_count)


(n, k) = map(int, input().split())
a = p = 0
for i in map(ord, sorted(input())):
	if i - a > 1:
		p += i - 96
		a = i
		k -= 1
	if k == 0:
		break
print((p, -1)[k > 0])


(n, k) = (int(x) for x in input().split())
s = input()
s = list(s)
s.sort()
c = 1
res = ord(s[0]) - 96
prev = ord(s[0])
for i in range(1, n):
	if c >= k:
		break
	if ord(s[i]) > prev + 1:
		c += 1
		res += ord(s[i]) - 96
		prev = ord(s[i])
if c >= k:
	print(res)
else:
	print(-1)


(n, k) = [int(i) for i in input().split()]
s = sorted(list(input()))
x = '' + s[0]
ans = ord(s[0]) - 96
l = 1
for i in range(1, n):
	if l == k:
		break
	if ord(s[i]) - ord(x[l - 1]) >= 2:
		l += 1
		x += s[i]
		ans += ord(s[i]) - 96
if l != k:
	print(-1)
else:
	print(ans)


w = list(map(int, list(input().strip().split())))
q = sorted(str(input().strip().split()[0]))
q = list(map(lambda x: ord(x) - 96, q))
i = 0
j = 0
c = 0
l = -1
while i < w[0] and j < w[1]:
	if q[i] - l >= 2:
		c = c + q[i]
		l = q[i]
		j = j + 1
	i = i + 1
if j == w[1]:
	print(c)
else:
	print(-1)


(n, k) = map(int, input().split())
s = input()
stages = [x for x in s]
stages.sort()
res = []
for (i, x) in enumerate(stages):
	if len(res) == 0:
		res.append(x)
	elif ord(x) - ord(res[-1]) > 1:
		res.append(x)
	if len(res) >= k:
		break
if len(res) < k:
	print(-1)
else:
	num = 0
	for x in res:
		num += ord(x) - ord('a') + 1
	print(num)


(n, m) = map(int, input().split())
s = input()
l = []
for e in s:
	l.append(e)
l.sort()
a = []
a.append(l[0])
del l[0]
su = ord(a[0]) - ord('a') + 1
flag = 0
while len(a) < m:
	i = 0
	while ord(l[i]) - ord('a') + 1 < ord(a[-1]) - ord('a') + 3:
		if i == len(l) - 1:
			print(-1)
			flag = 1
			break
		i += 1
	if flag == 1:
		break
	a.append(l[i])
	del l[i]
	su += ord(a[-1]) - ord('a') + 1
if not flag:
	print(su)


(n, k) = map(int, input().split())
l = sorted(input())
s = ord(l[0]) - 96
if k == 1:
	print(s)
else:
	(c, d, f) = (0, 1, 0)
	for x in range(1, n):
		if ord(l[x]) - ord(l[c]) > 1:
			s += ord(l[x]) - 96
			c = x
			d += 1
		if d == k:
			f = 1
			break
	if f == 1:
		print(s)
	else:
		print(-1)


for _ in range(1):
	(n, k) = map(int, input().split())
	s = list(input())
	s.sort()
	prev = ord(s[0])
	cur = ord(s[0]) - ord('a') + 1
	ini = k
	k -= 1
	for i in range(1, n):
		if ord(s[i]) - prev >= 2 and k > 0:
			cur += ord(s[i]) - ord('a') + 1
			prev = ord(s[i])
			k -= 1
		if k == 0:
			break
	if ini == 0:
		print(0)
	elif k > 0:
		print(-1)
	else:
		print(cur)


import sys
(n, k) = map(int, input().split())
s = input()
L = [''] * len(s)
for i in range(len(s)):
	L[i] = s[i]
L.sort()
s = 'abcdefghijklmnopqrstuvwxyz'
for i in range(len(L)):
	ind = s.find(L[i])
	cur = k - 1
	sm = ind + 1
	for j in range(i, len(L)):
		if s.find(L[j]) > ind + 1:
			ind = s.find(L[j])
			cur -= 1
			sm += ind + 1
		if cur == 0:
			print(sm)
			sys.exit()
print(-1)


(n, k) = map(int, input().split(' '))
letters = sorted(input())
answer = []

def wOf(answer):
	w = 0
	for letter in answer:
		w += ord(letter) - 96
	return w

def iwOf(letter):
	return ord(letter) - 96

def difference(a, b):
	return ord(a) - 96 - (ord(b) - 96)
i = 1
answer.append(letters[0])
lastLetter = letters[0]
while len(answer) < k:
	if i > len(letters) - 1:
		break
	if difference(letters[i], lastLetter) > 1:
		answer.append(letters[i])
		lastLetter = letters[i]
	i += 1
if len(answer) == k:
	print(wOf(answer))
else:
	print(-1)


(n, k) = map(int, input().split())
s = list(input())
s.sort()
e = 1
ans = ord(s[0]) - 96
ce = s[0]
for i in range(1, n):
	if e == k:
		break
	if ord(s[i]) - ord(ce) >= 2:
		e += 1
		ce = s[i]
		ans += ord(s[i]) - 96
print(ans if e == k else -1)


(n, k) = map(int, input().split())
s = input()
s = sorted(set(s))
li = [ord(i) - 96 for i in s]
ans = 0
min_ = li[0]
count = 0
for i in range(1, len(li)):
	if li[i] > min_ + 1:
		ans += li[i]
		min_ = li[i]
		count += 1
	if count == k - 1:
		break
if k == 1:
	print(li[0])
elif count != k - 1:
	print(-1)
else:
	print(ans + li[0])


(n, k) = [int(i) for i in input().split()]
s = list(set(list(input())))
s.sort()
if len(s) < k:
	print('-1')
else:
	ans = 0
	prev = s[0]
	j = 0
	i = 0
	while j < k and i < len(s):
		if ord(s[i]) == ord(prev) + 1:
			i += 1
			continue
		ans += ord(s[i]) - ord('a') + 1
		j += 1
		prev = s[i]
		i += 1
	if j < k:
		print('-1')
	else:
		print(ans)


(n, k) = list(map(int, input().split()))
k -= 1
s = list(map(str, input()))
s.sort()
a = s[0]
ans = ord(a) - ord('a') + 1
for i in range(1, n):
	if k == 0:
		break
	if ord(s[i]) - ord(a) >= 2:
		a = s[i]
		ans += ord(a) - ord('a') + 1
		k -= 1
if k:
	print(-1)
else:
	print(ans)


import string
(n, k) = map(int, input().split())
s = input()
alph = string.ascii_lowercase
dp = [[100000] * 26 for i in range(k)]
for i in range(26):
	if s.find(alph[i]) != -1:
		dp[0][i] = i + 1
for i in range(1, k):
	for j in range(26):
		for z in range(j - 1):
			dp[i][j] = min(dp[i][j], dp[i - 1][z] + dp[0][j])
if min(dp[-1]) == 100000:
	print(-1)
else:
	print(min(dp[-1]))


(n, k) = map(int, input().split())
s = list(input())
s.sort()
i = 0
j = ord(s[0]) - 2
count = 0
ANS = 0
while i < n:
	if ord(s[i]) >= j + 2:
		j = ord(s[i])
		ANS += j - 96
		count += 1
		if count == k:
			break
		else:
			i += 1
	else:
		i += 1
if count == k:
	print(ANS)
else:
	print(-1)


(n, k) = map(int, input().split())
s = input()
s = sorted(s)
final = 99999999999
imp = True
for i in range(n):
	st = [s[i]]
	w = ord(st[-1]) - 96
	c = i
	while len(st) < k and c + 1 < n:
		w1 = ord(st[-1]) - 96
		c += 1
		w2 = ord(s[c]) - 96
		if w2 - w1 >= 2:
			w += w2
			st.append(s[c])
	if len(st) == k:
		if w < final:
			final = w
		imp = False
	else:
		break
if imp:
	print(-1)
else:
	print(final)


import math
import os
import random
import re
import sys
import functools
from operator import itemgetter, attrgetter
(n, k) = list(map(int, input().strip().split()))
s = sorted(list(map(ord, input().strip())))
(a, p) = (list(), 0)
a.append(s[p])
for i in range(1, n):
	if s[i] - s[p] >= 2:
		a.append(s[i])
		p = i
s = list(map(lambda x: x - ord('a') + 1, a))
p = -1 if len(s) < k else functools.reduce(lambda a, b: a + b, s[:k])
print('{}'.format(p))


(n, k) = input().split()
n = int(n)
k = int(k)
string = list(input())
string.sort()
summer = 0
summer += ord(string[0]) - 96
prev = ord(string[0]) - 96
counter = 1
for i in range(1, n):
	if counter == k:
		break
	temp = ord(string[i]) - 96
	if temp > prev and temp != prev + 1:
		summer += temp
		counter += 1
		prev = temp
if counter != k:
	print(-1)
else:
	print(summer)


(n, k) = [int(i) for i in input().split()]
data = [ord(i) - 96 for i in input()]
data.sort()
ret = data[0]
left = 0
right = 1
k -= 1
while k:
	if right >= n:
		ret = -1
		break
	if data[right] - data[left] >= 2:
		ret += data[right]
		k -= 1
		left = right
	right += 1
print(ret)


(n, k) = map(int, input().split(' '))
L = list(input())
L.sort()
s = 0
last = -10
for ch in L:
	c = ord(ch[0]) - ord('a')
	if c > last + 1:
		if k > 0:
			k -= 1
			s += c + 1
			last = c
if k > 0:
	print('-1')
else:
	print(s)


(n, k) = map(int, input().split())
s = sorted(input())
threshold = ord('`')
weight = 0
length = 0
last = chr(ord('a') - 2)
possible = False
for i in range(n):
	if ord(s[i]) >= ord(last) + 2:
		last = s[i]
		weight += ord(s[i]) - threshold
		length += 1
		if length == k:
			print(weight)
			possible = True
if not possible:
	print(-1)


import math
import itertools
getInputList = lambda : list(input().split())
getInputIntList = lambda : list(map(int, input().split()))
d = ['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']
dset = {}
for i in range(1, 27):
	dset[d[i - 1]] = i
(n, k) = getInputIntList()
arr = list(input())
arr.sort()
newarr = []
newarr.append(dset[arr[0]])
for i in arr[1:]:
	if len(newarr) == k:
		break
	if newarr[len(newarr) - 1] + 1 < dset[i]:
		newarr.append(dset[i])
if len(newarr) < k:
	print(-1)
else:
	print(sum(newarr))


import itertools
import collections
import sys
import math
input = sys.stdin.readline
read = lambda : input().rstrip()
puts = sys.stdout.write

def read_ints():
	yield from map(int, read().split())

def main():
	(n, k) = read_ints()
	s = sorted(read())
	cnt = 0
	ans = 0
	last_taken = -1
	for (i, c) in enumerate(s):
		if cnt == k:
			break
		if not i or ord(c) - ord(s[last_taken]) >= 2:
			cnt += 1
			last_taken = i
			ans += ord(c) - ord('a') + 1
	print(-1 if cnt < k else ans)
main()


(n, k) = list(map(int, input().split()))
stages = list(input())
stages.sort()
rock = [stages[0]]
for i in range(n - 1):
	if ord(stages[i + 1]) > ord(rock[-1]) + 1 and len(rock) < k:
		rock.append(stages[i + 1])
if len(rock) == k:
	print(sum(list(map(ord, rock))) - len(rock) * 96)
else:
	print(-1)


d = 'abcdefghijklmnopqrstuvwxyz'
(n, k) = map(int, input().split())
s = sorted(input())
c = [d.find(str(i)) + 1 for i in s]
(summa, x, i, step) = (c[0], 1, 0, 1)
while x < k and i + step < n:
	if c[i + step] - c[i] > 1:
		summa += c[i + step]
		i += step
		step = 1
		x += 1
	else:
		step += 1
if x < k:
	print(-1)
else:
	print(summa)


(n, k) = [int(x) for x in input().split()]
s = list(input())
s.sort()
ans = ord(s[0]) - ord('a') + 1
j = i = 0
temp = 1
while temp < k and i < n - 1:
	diff = ord(s[i + 1]) - ord(s[j])
	if diff > 1:
		temp += 1
		ans += ord(s[i + 1]) - ord('a') + 1
		j = i + 1
	i += 1
if temp == k:
	print(ans)
else:
	print(-1)


def main():
	[n, k] = map(int, input().split())
	stages = [char for char in input()]
	stages.sort()
	index = 0
	stages_build = [stages[0]]
	while len(stages_build) < k:
		try:
			a = ord(stages[index])
			index = next((i for i in range(index + 1, n) if ord(stages[i]) - a > 1))
			stages_build += [stages[index]]
		except StopIteration:
			break
	if len(stages_build) < k:
		print(-1)
	else:
		a = ord('a')
		print(sum((ord(char) - a for char in stages_build)) + k)
main()


import sys, math
from fractions import gcd
from itertools import permutations
debug = 0
if debug:
	f = open('input.txt', 'r')
	input = f.readline
else:
	input = sys.stdin.readline

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

def _main():
	(n, k) = mp()
	a = list(input().strip())
	a.sort()
	ans = []
	for i in range(n):
		if len(ans) == 0 or abs(ord(a[i]) - ord(ans[-1])) > 1:
			ans += [a[i]]
	if len(ans) < k:
		print(-1)
		return
	sum = 0
	for i in range(k):
		sum += ord(ans[i]) - ord('a') + 1
	print(sum)
_main()


(n, k) = list(map(int, input().split()))
s = list(set(input()))
s.sort()
bad = ''
am = 0
ans = 0
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in s:
	if i == bad:
		continue
	else:
		am += 1
		ans += alpha.index(i) + 1
		if i != 'z':
			bad = alpha[alpha.index(i) + 1]
		if am == k:
			print(ans)
			exit()
print(-1)


[n, k] = [int(x) for x in input().split()]
s = input()
A = [0] * 26
for i in s:
	A[ord(i) - ord('a')] += 1
c = 0
wt = 0
i = 0
while i < 26:
	if A[i] != 0:
		wt += i + 1
		c += 1
		i += 1
		if c == k:
			break
	i += 1
if c != k:
	print('-1')
else:
	print(wt)


(n, k) = [int(x) for x in input().split()]
s = input()
p = sorted(s)
d = [ord(p[0])]
count = 0
for i in range(1, n):
	if ord(p[i]) > ord(p[count]) + 1 and k > 1:
		d.append(ord(p[i]))
		count = i
		if len(d) == k:
			break
if len(d) == k:
	print(sum(d) - k * 96)
else:
	print('-1')


(n, k) = map(int, input().strip().split(' '))
s = list(input())
s.sort()
freq = [0 for i in range(26)]
for i in range(n):
	freq[ord(s[i]) - 97] += 1
cnt = 0
ans = 0
prev = -2
for i in range(26):
	if freq[i] != 0 and i - prev >= 2:
		cnt += 1
		ans += i
		prev = i
		if cnt == k:
			break
if cnt == k:
	print(ans + k)
else:
	print(-1)


import functools
import time

def timer(func):

	@functools.wraps(func)
	def wrapper(*args, **kwargs):
		stime = time.perf_counter()
		res = func(*args, **kwargs)
		elapsed = time.perf_counter() - stime
		print(f'{func.__name__} in {elapsed:.4f} secs')
		return res
	return wrapper

class solver:

	def __init__(self):
		pass

	def __call__(self):
		(n, m) = map(int, input().strip().split())
		s = list(input().strip())
		s = list(set([ord(e) - ord('a') + 1 for e in s]))
		s.sort()
		last = -100
		pos = 0
		ans = list()
		while pos < len(s):
			if s[pos] - last >= 2:
				ans.append(s[pos])
				last = s[pos]
			pos += 1
		if len(ans) >= m:
			print(sum(ans[:m]))
		else:
			print('-1')
solver()()


(n, k) = [*map(int, input().split())]
st = sorted(input())
li = ['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']
newli = []
for i in st:
	newli.append(li.index(i) + 1)
if k == 1:
	print(newli[0])
	quit()
else:
	addvalue = newli[0]
	addtime = 1
	cursor1 = 0
	cursor2 = 1
	while addtime < k:
		try:
			newli[cursor2]
		except:
			print(-1)
			quit()
		if newli[cursor2] - newli[cursor1] <= 1:
			cursor2 += 1
		else:
			addvalue += newli[cursor2]
			cursor1 = cursor2
			cursor2 += 1
			addtime += 1
	print(addvalue)


import sys
import math
import bisect
import itertools
import random

def main():
	(n, m) = map(int, input().split())
	s = set()
	for c in input():
		s.add(ord(c) - ord('a') + 1)
	dp = []
	for i in range(27):
		dp.append([10 ** 9] * (m + 1))
	dp[0][0] = 0
	for i in range(1, 27):
		if i in s:
			for j in range(1, m + 1):
				if j == 1:
					dp[i][j] = i
				else:
					for k in range(1, i - 1):
						dp[i][j] = min(dp[i][j], dp[k][j - 1] + i)
	min_val = 10 ** 9
	for i in range(1, 27):
		val = dp[i][m]
		min_val = min(min_val, val)
	if min_val == 10 ** 9:
		print(-1)
	else:
		print(min_val)
main()


(n, k) = map(int, input().split())
s = sorted(str(input()))
l = []
k -= 1
for i in s:
	l.append(ord(i) - 96)
ans = l[0]
while k != 0:
	try:
		if l[1] - l[0] >= 2:
			ans += l[1]
			l.pop(0)
			k -= 1
		else:
			l.pop(1)
	except:
		if k > 0:
			print(-1)
			quit()
print(ans)


def solve(s, k):
	s = [ord(x) - ord('a') + 1 for x in sorted(set(s))]
	n = len(s)
	if n < k:
		return -1
	min_so_far = float('inf')
	for comb in combinations(s, k, -1, []):
		min_so_far = min(min_so_far, comb)
	if min_so_far == float('inf'):
		return -1
	return min_so_far

def combinations(s, k, idx, current):
	if len(current) == k:
		total = sum(current)
		yield total
	else:
		for i in range(idx + 1, len(s)):
			if len(current) and s[i] - current[-1] < 2:
				continue
			current.append(s[i])
			yield from combinations(s, k, i, current)
			current.pop()

def main():
	(n, k) = [int(x) for x in input().strip().split()]
	s = input().strip()
	print(solve(s, k))
main()


(A, B) = [int(x) for x in input().split()]
st = input()
count = 0
a = list(st)
arr = []
new = []
res = 0
i = 0
for i in range(0, len(a)):
	arr.append(int(ord(a[i])) - 96)
arr.sort()
temp = []
temp = arr.copy()
for i in range(0, len(arr) - 1):
	if temp[i + 1] == temp[i] + 1:
		temp[i + 1] = 0
	if arr[i + 1] == arr[i]:
		temp[i] = 0
for i in range(0, len(temp)):
	if temp[i] != 0:
		new.append(temp[i])
for i in range(0, len(new) - 1):
	if new[i + 1] == new[i] + 1:
		new[i + 1] = 0
for i in range(0, len(new)):
	if new[i] != 0 and count < B:
		res = res + new[i]
		count = count + 1
	if count == B:
		case = 1
	else:
		case = 0
if case == 1:
	print(res)
if case == 0:
	print('-1')


alph = 'abcdefghijklmnopqrstuvwxyz'
(n, k) = map(int, input().split())
s = list(input())
s.sort()
last = ord(s[0])
k -= 1
c = last - 96
for i in range(1, n):
	if k == 0:
		break
	if ord(s[i]) - last > 1:
		last = ord(s[i])
		k -= 1
		c += last - 96
if k == 0:
	print(c)
else:
	print(-1)


(n, k) = map(int, input().split())
s = input()
ls = [s[i] for i in range(n)]
ls.sort()
new_ls = []
for i in range(n):
	if i == 0:
		new_ls.append(ls[i])
	elif ord(ls[i]) - ord(new_ls[-1]) > 1:
		new_ls.append(ls[i])
	if len(new_ls) == k:
		break
if len(new_ls) == k:
	ans = 0
	for i in range(k):
		ans += ord(new_ls[i]) - 97 + 1
	print(ans)
else:
	print(-1)


(n, k) = map(int, input().split())
string = list(input())
string.sort()
sum = 0
precedent = -42
for letter in string:
	if ord(letter) > precedent + 1:
		precedent = ord(letter)
		sum += ord(letter) - 96
		k -= 1
	if k == 0:
		break
if k > 0:
	print(-1)
else:
	print(sum)


(n, q) = map(int, input().split())
n = int(n)
q = int(q)
l = input()
k = []
if q == 1:
	print(ord(min(l)) - 96)
else:
	for i in range(len(l)):
		k.append(l[i])
	k = list(set(k))
	li = sorted(k)
	i = 0
	s = ' '
	for i in range(len(li)):
		if ord(s[-1]) + 1 == ord(li[i]):
			pass
		else:
			s += li[i]
	s = s[1:q + 1]
	su = 0
	if len(s) == q:
		for j in range(len(s)):
			su += ord(s[j]) - 96
	if su == 0:
		su = -1
	print(su)


(n, k) = map(int, input().split())
s = sorted(input())
w = ord(s[0]) - 96
temp = s[0]
count = 1
for i in range(1, n):
	if count == k:
		break
	if ord(s[i]) - ord(temp) < 2:
		continue
	else:
		w += ord(s[i]) - 96
		temp = s[i]
		count += 1
if count == k:
	print(w)
else:
	print(-1)


(n, k) = map(int, input().split())
a = input()
t = [0 for _ in range(30)]
for x in a:
	t[ord(x) - ord('a')] = 1
ans = tmp = i = 0
while i < 26:
	if t[i]:
		i += 1
		tmp += 1
		ans += i
	if tmp == k:
		break
	i += 1
if tmp < k:
	print(-1)
else:
	print(ans)


(n, k) = list(map(int, input().split()))
a = [0] * 26
inn = input()
for i in inn:
	a[ord(i) - ord('a')] += 1
ans = 0
i = 0
anss = 0
while i < 26:
	if a[i]:
		ans += 1
		anss += i + 1
		i += 1
	i += 1
	if ans == k:
		break
if ans < k:
	print(-1)
else:
	print(anss)


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

def solve():
	(n, k) = input_ints()
	s = input()
	ans = 0
	i = 0
	while i < 26 and k:
		if chr(i + ord('a')) in s:
			ans += i + 1
			i += 1
			k -= 1
		i += 1
	if k:
		ans = -1
	print(ans)
solve()


(n, k) = list(map(int, input().split()))
sol = 1
s = input()
ss = sorted(s)
last = ord('a') - 2
ans = 0
length = 0
for i in range(n):
	if ord(ss[i]) >= last + 2:
		last = ord(ss[i])
		ans += ord(ss[i]) - ord('a') + 1
		length += 1
	if length >= k:
		if sol == 1:
			print(ans)
			sol = 0
if sol == 1:
	print(-1)


import collections, atexit, math, sys
from functools import cmp_to_key
sys.setrecursionlimit(1000000)

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

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

	def dprint(*args, **kwargs):
		pass

def memo(func):
	cache = {}

	def wrap(*args):
		if args not in cache:
			cache[args] = func(*args)
		return cache[args]
	return wrap

@memo
def comb(n, k):
	if k == 0:
		return 1
	if n == k:
		return 1
	return comb(n - 1, k - 1) + comb(n - 1, k)
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()
s = input()
sl = list(s)
sl.sort()
re = [sl[0]]
for x in sl[1:]:
	if ord(re[-1]) + 1 >= ord(x):
		continue
	re.append(x)
if len(re) < K:
	print(-1)
	sys.exit()
res = sum(map(ord, re[:K])) - ord('a') * K + K
print(res)


(n, k) = map(int, input().split())
s = input()
w = 0
count1 = 0
count2 = 0
x = []
for i in range(int(n)):
	x.append(ord(s[i]) - 96)
x.sort()
j = x[0]
w += x[0]
for l in range(int(n)):
	if x[l] - j >= 2 and x[l] <= 26:
		j = x[l]
		count1 += 1
		if count1 <= k - 1:
			w += x[l]
			count2 += 1
if count2 == k - 1:
	print(w)
else:
	print(-1)


(_, k) = map(int, input().split())
s = sorted(set(input()))
stages = s[0]
for ch in s[1:]:
	if ord(ch) - ord(stages[-1]) > 1:
		stages += ch
print(-1 if len(stages) < k else sum((ord(ch) - 96 for ch in stages[:k])))


input_list = list(map(int, input().split()))
input_alpha = list(input())
total_stage = input_list[0]
select_stage = input_list[1]
num_alpha = list(map(ord, input_alpha))
num_alpha_sorted = sorted(num_alpha)
ans_list = []
cur_min_weight = 0
for i in num_alpha_sorted:
	if len(ans_list) == select_stage:
		break
	if cur_min_weight + 2 <= i:
		ans_list.append(i)
		cur_min_weight = i
if len(ans_list) < select_stage:
	print(-1)
else:
	sum_list = 0
	for j in ans_list:
		sum_list = sum_list + j - 96
	print(sum_list)


(n, m) = map(int, input().split())
d = [0] * 26
for c in input():
	d[ord(c) - ord('a')] += 1
i = 0
ans = 0
while i < 26 and m:
	while i < 26 and (not d[i]):
		i += 1
	if i == 26:
		break
	ans += i + 1
	i += 2
	m -= 1
print(-1 if m else ans)


(n, a) = map(int, input().split())
s = sorted(input())
f = [s[0]]
ans = 0
l = 0
for i in range(a - 1):
	for j in range(n):
		if ord(s[j]) > ord(f[l]) + 1:
			f.append(s[j])
			l += 1
			break
if len(f) == a:
	for x in f:
		ans += ord(x) - 96
	print(ans)
else:
	print(-1)


a = 'abcdefghijklmnopqrstuvwxyz'
(n, k) = map(int, input().split())
s = list(input())
s.sort()
g = a.index(s[0]) + 1
k -= 1
p = 1
m = ''
m += s[0]
while k != 0:
	if a.index(s[p]) - a.index(m[len(m) - 1]) >= 2:
		m += s[p]
		g += a.index(s[p]) + 1
		k -= 1
	p += 1
	if p == n and k != 0:
		print(-1)
		exit()
print(g)


def getWeight(a):
	return ord(a) - ord('a') + 1
(n, k) = input().strip().split(' ')
n = int(n)
k = int(k)
if k <= 0:
	print('0')
	exit(0)
if n <= 0:
	print('-1')
	exit(0)
if k > 14:
	print('-1')
	exit(0)
s = set()
st = input().strip()
for x in st:
	s.add(x)
count = 0
skip = False
ret = 0
prev = -2
for x in sorted(s):
	if count == k:
		break
	if skip == True:
		if getWeight(x) == prev + 1:
			skip = False
			continue
	skip = True
	prev = getWeight(x)
	ret += prev
	count += 1
if count < k:
	print(-1)
	exit(0)
print(ret)


(n, k) = map(int, input().split())
a = sorted(map(ord, input()))
r = a[:1]
for x in a[1:]:
	if x - r[-1] > 1:
		r.append(x)
print([sum(r[:k]) - 96 * k, -1][len(r) < k])


(n, k) = map(int, input().split())
s = input()
mat = [ord(i) - 96 for i in s]
mat = sorted(mat)
(res, step) = (0, -1)
for i in mat:
	if i - step > 1:
		k -= 1
		res += i
		step = i
	if k == 0:
		break
print(res if k == 0 else -1)


def find_next(checked_letters, letters):
	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']
	lowest = 'z'
	index = -1
	for l in range(len(letters)):
		letter = letters[l]
		letter_pos = alphabet.index(letter)
		if alphabet.index(lowest) >= letter_pos:
			present = False
			for check in checked_letters:
				if check[0] == letter and check[1] == l:
					present = True
			if present == False:
				lowest = letter
				index = l
	return (lowest, index)
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']
values = input()
(n, k) = values.split()
letters = input()
checked_letters = []
list_set = []
i = 0
crash = False
while i < int(k) and crash == False:
	(next_letter, index) = find_next(checked_letters, letters)
	checked_letters.append([next_letter, index])
	pos = alphabet.index(next_letter)
	check = False
	for value in list_set:
		if alphabet.index(value) >= pos or pos - alphabet.index(value) <= 1:
			check = True
	if check == False:
		list_set.append(next_letter)
		i += 1
	if len(list_set) < int(k) and len(checked_letters) == int(n):
		crash = True
if crash == False:
	sum = 0
	for let in list_set:
		sum = sum + alphabet.index(let) + 1
	print(sum)
else:
	print('-1')


(n, k) = map(int, input().split())
stages = input()
alphabet = [0] * 26
for i in range(n):
	ch = stages[i]
	index = ord(ch) - 97
	alphabet[index] = 1
total = 0
count = 0
i = -1
while count < k:
	i += 1
	if i >= 26:
		break
	if alphabet[i] > 0:
		count += 1
		total += i + 1
		i += 1
if count < k:
	total = -1
print(total)


def merge_sort(s):
	if len(s) <= 1:
		return s
	else:
		L = s[:len(s) // 2]
		R = s[len(s) // 2:]
		return merge(merge_sort(L), merge_sort(R))

def merge(A, B):
	i = 0
	j = 0
	Ans = []
	while i != len(A) and j != len(B):
		if ord(A[i]) < ord(B[j]):
			Ans.append(A[i])
			i += 1
		else:
			Ans.append(B[j])
			j += 1
	Ans += A[i:] + B[j:]
	return Ans
(n, k) = map(int, input().split())
s = list(input())
s = merge_sort(s)
ans = ord(s[0]) - 96
l = 1
t = s[0]
used = 1
for i in range(1, k):
	for j in range(l, n):
		if ord(s[j]) - ord(t) >= 2:
			ans += ord(s[j]) - 96
			t = s[j]
			l = j
			used += 1
			break
if k > 1 and ans == ord(s[0]) - 96 or used < k:
	ans = -1
print(ans)


alf = list('abcdefghijklmnopqrstuvwxyz')
(n, k) = map(int, input().split())
s = list(set(list(input())))
s.sort()
if len(s) < k:
	print(-1)
	exit(0)
q = [s[0]]
for i in range(1, len(s)):
	if alf.index(s[i]) - alf.index(q[len(q) - 1]) > 1:
		q.append(s[i])
if len(q) < k:
	print(-1)
	exit(0)
m = 0
for i in range(k):
	m += alf.index(q[i]) + 1
print(m)


(n, k) = map(int, input().split())
s = list(input())
s = sorted(s)
pred = -100
a = []
summa = 0
for elem in s:
	if len(a) >= k:
		for j in range(k):
			summa += a[j]
		print(summa)
		break
	if ord(elem) - pred >= 2:
		a.append(ord(elem) - ord('a') + 1)
		pred = ord(elem)
else:
	if len(a) >= k:
		for j in range(k):
			summa += a[j]
		print(summa)
	else:
		print(-1)


import string
arr = [0]
let = string.ascii_lowercase
for i in let:
	arr.append(i)
(n, k) = map(int, input().split())
s = sorted(set(input()))
cur = -1
new = []
for i in s:
	if arr.index(i) > cur + 1:
		cur = arr.index(i)
		new.append(cur)
		if len(new) == k:
			print(sum(new))
			break
else:
	print(-1)


import string

def code5():
	(n, k) = map(int, input().split())
	s = input()
	a = []
	for i in string.ascii_lowercase:
		a.append(i)
	w = 0
	i = 0
	while i < 26 and k != 0:
		if a[i] in s:
			w = w + ord(a[i]) - 96
			i += 2
			k -= 1
		else:
			i += 1
	if k == 0:
		print(w)
	else:
		print('-1')
code5()


(available, needed) = map(int, input().split())
stages = sorted(list(input()), key=lambda x: ord(x))
result = 0
rocket_stages = 'A'
for current_stage in stages:
	if ord(current_stage) - ord(rocket_stages[-1]) > 1:
		rocket_stages += current_stage
		result += ord(current_stage) - 96
	if len(rocket_stages[1:]) == needed:
		break
if result == 0 or len(rocket_stages[1:]) < needed:
	print(-1)
else:
	print(result)


(n, k) = map(int, input().split())
s = input()
arr = []
for el in s:
	arr.append(el)
arr = sorted(arr)
count = 0
idx = 0
ans = 0
prev = -1000000
while count < k:
	if idx >= n:
		ans = -1
		break
	if ord(arr[idx]) - ord('a') + 1 - prev >= 2:
		ans += ord(arr[idx]) - ord('a') + 1
		count += 1
		prev = ord(arr[idx]) - ord('a') + 1
	idx += 1
print(ans)


(n, k) = [int(x) for x in input().split()]
s = sorted(list(input()))
alp = list('abcdefghijklmnopqrstuvwxyz')
steps = []
res = 0
flag = 0
while len(steps) < k:
	if s == []:
		flag = 1
		print(-1)
		break
	elif steps == []:
		steps.append(s[0])
		res += alp.index(s[0]) + 1
		s.pop(0)
	elif alp.index(s[0]) - alp.index(steps[-1]) >= 2:
		steps.append(s[0])
		res += alp.index(s[0]) + 1
		s.pop(0)
	else:
		s.pop(0)
if flag == 0:
	print(res)


(n, k) = list(map(int, input().split()))
(s, l) = (sorted(input()), [])
for i in range(len(s)):
	if i == 0:
		l.append(ord(s[i]) - 96)
	elif ord(s[i]) - 96 - l[-1] > 1:
		l.append(ord(s[i]) - 96)
	if len(l) == k:
		print(sum(l))
		break
else:
	print(-1)


total = input()
k = int(total.split(' ')[1])
inp = input()
inp = sorted(inp)
j = 0
sum = 0
last = 90
for i in range(0, len(inp)):
	if i == 0:
		j += 1
		last = ord(inp[i])
		sum += ord(inp[i]) - 96
		if j >= k:
			break
		continue
	if ord(inp[i]) - last > 1:
		j += 1
		last = ord(inp[i])
		sum += ord(inp[i]) - 96
	if j >= k:
		break
if j != k:
	print('-1')
else:
	print(sum)


alfa = 'abcdefghijklmnopqrstuvwxyz'
d = {}
for (i, x) in enumerate(alfa):
	d[x] = i + 1
(n, k) = map(int, input().split())
s = list(input())
s.sort()
res = d[s[0]]
y = res
k -= 1
for (i, x) in enumerate(s):
	if i == 0:
		continue
	if k == 0:
		break
	if d[x] - y > 1:
		res += d[x]
		y = d[x]
		k -= 1
if k == 0:
	print(res)
else:
	print(-1)


(n, k) = map(int, input().split())
s = sorted(input())
ar = []
for i in range(26):
	ar.append(0)
for i in range(len(s)):
	ar[ord(s[i]) - 97] += 1
last = ord(s[0]) - 97
ans = ord(s[0]) - 96
t = 1
for i in range(last + 2, 26):
	if ar[i] == 0 or t == k or i - last < 2:
		continue
	last = i
	ans += i + 1
	t += 1
if t == k:
	print(ans)
else:
	print(-1)


import string as st
inp = list(map(int, input().split(' ')))
stages = sorted(input())
latin = list(st.ascii_lowercase)
cost = count = prev = 0
for i in range(inp[0]):
	if i == 0:
		cost += latin.index(stages[i]) + 1
		count += 1
	elif latin.index(stages[i]) - prev > 1 and count < inp[1]:
		prev = latin.index(stages[i])
		cost += prev + 1
		count += 1
if count == inp[1]:
	print(cost)
else:
	print(-1)


(n, k) = map(int, input().split())
s = sorted(list(set(input())))
stages = []
for i in range(len(s)):
	if i == 0:
		stages.append(s[i])
	elif ord(s[i]) - ord(stages[-1]) >= 2:
		stages.append(s[i])
	if len(stages) == k:
		break
if len(stages) == k:
	minsum = 0
	for i in range(k):
		minsum += ord(stages[i]) - 96
	print(minsum)
else:
	print(-1)


ch = 'abcdefghijklmnopqrstuvwxyz'
(n, k) = map(int, input().split())
s = sorted(list(input()))
ans = s[0]
for i in range(1, n):
	if ch.index(s[i]) - ch.index(ans[-1]) > 1:
		ans += s[i]
print(sum(map(lambda i: ord(i) - ord('a') + 1, ans[:k])) if len(ans) >= k else -1)


(n, k) = map(int, input().split())
s = sorted(list(input()))
selected = 1
a = ord('a') - 1
cur = ord(s[0])
weight = cur - a
i = 1
while i < n and selected < k:
	if ord(s[i]) - cur > 1:
		selected += 1
		cur = ord(s[i])
		weight += cur - a
	i += 1
if selected == k:
	print(weight)
else:
	print(-1)


(n, k) = map(int, input().split())
brr = input()
arr = [0] * n
for i in range(n):
	arr[i] = ord(brr[i]) + 1 - ord('a')
arr.sort()
if k > n:
	print('-1')
else:
	sm = arr[0]
	k -= 1
	s = 0
	for i in range(1, n):
		if k == 0:
			break
		if arr[i] > arr[s] + 1:
			sm += arr[i]
			s = i
			k -= 1
	if k:
		print('-1')
	else:
		print(sm)


orda = ord('a') - 1
(n, k) = list(map(int, input().split()))
L = sorted(list(set(list(map(lambda i: ord(i) - orda, list(input()))))))
n = len(L)
ans = L[0]
x = 1
l = L[0]
for i in range(1, n):
	if k == x:
		break
	if l <= L[i] - 2:
		ans += L[i]
		x += 1
		l = L[i]
if k != x:
	print(-1)
else:
	print(ans)


import string
(n, m) = map(int, input().split())
a = input()
k = 0
j = 1
q = 0
b = string.ascii_lowercase
for i in b:
	p = ord(i)
	if i in a and p - q > 1:
		if j - 1 == m:
			break
		k += p + 1 - 97
		q = p
		j += 1
if j - 1 < m:
	print(-1)
else:
	print(k)


def main():
	(n, m) = map(int, input().split())
	l = sorted(map(ord, input()), reverse=True)
	r = [l.pop() - 96]
	try:
		while len(r) < m:
			while r[-1] > l[-1] - 98:
				del l[-1]
			r.append(l.pop() - 96)
		print(sum(r))
	except IndexError:
		print(-1)
main()


(n, k) = map(int, input().split())
s = input()
l = list((ord(i) - 96 for i in s))
l.sort()
l = list(set(l))
su = 0
for i in range(len(l) - 1):
	if l[i] + 1 == l[i + 1]:
		l[i + 1] = 0
l.sort()
while True:
	if l[0] == 0:
		l.pop(0)
	else:
		break
if len(l[:k]) == k:
	print(sum(l[:k]))
else:
	print(-1)


(n, k) = list(map(int, input().split()))
data = sorted(list(input()))
data = list(map(lambda x: ord(x) - ord('a') + 1, data))
result = 0
used = 0
idx = 0
prev = -2
for d in data:
	if d > prev + 1:
		result += d
		prev = d
		used += 1
	if used == k:
		break
if used < k:
	print(-1)
else:
	print(result)


(n, k) = map(int, input().split())
s = sorted(input())
(ans, lst) = (0, ord('a') - 2)
for x in s:
	if ord(x) - lst >= 2:
		ans += ord(x) - ord('a') + 1
		lst = ord(x)
		k -= 1
		if k == 0:
			break
if k == 0:
	print(ans)
else:
	print(-1)


a = int(input().split()[1])
c = sorted(set(input()))
b = len(c)
k = c[0]
a -= 1
i = 1
s = ord(k) % 96
while a and i < b:
	if ord(c[i]) - ord(k) not in [1, 0]:
		s += ord(c[i]) % 96
		k = c[i]
		a -= 1
	i += 1
print(*([-1] if a else [s]))


(n, k) = map(int, input().split())
s1 = input()
s = []
for i in s1:
	s.append(i)
s.sort()
arr = [s[0]]
for i in range(1, n):
	if ord(arr[-1]) + 2 <= ord(s[i]):
		arr.append(s[i])
arr.sort()
if len(arr) < k:
	print(-1)
else:
	ans = 0
	for i in range(k):
		ans += ord(arr[i]) - 96
	print(ans)


(n, k) = map(int, input().split(' '))
s = map(ord, sorted(input()))
ans = cur = 0
for c in s:
	if c - cur > 1:
		ans += c - 96
		cur = c
		k -= 1
	if k == 0:
		break
if k > 0:
	print(-1)
else:
	print(ans)


from collections import deque as de
import math
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))
(n, k) = map(int, input().split())
kk = list(map(str, input()))
s = sorted(list(set(kk)))
if k > 13:
	print(-1)
else:
	dic = {}
	for (index, value) in enumerate('abcdefghijklmnopqrstuvwxyz'):
		dic[value] = index + 1
	ans = 0
	ans += dic[s[0]]
	k -= 1
	curr = s[0]
	for i in range(1, len(s)):
		if k:
			if dic[s[i]] > dic[curr] + 1:
				ans += dic[s[i]]
				curr = s[i]
				k -= 1
			if k == 0:
				break
	if k == 0:
		print(ans)
	else:
		print(-1)


(n, k) = map(int, input().split())
a = list(input())
a.sort()
x = 1
t = ord(a[0]) - 96
s = a[0]
for i in range(1, n):
	if x == k:
		break
	if ord(a[i]) - ord(s) >= 2:
		s = a[i]
		t += ord(a[i]) - 96
		x += 1
if x < k:
	print(-1)
else:
	print(t)


(n, m) = [int(i) for i in input().split()]
a = [ord(i) - 96 for i in list(input())]
a.sort()
ans = 0
j = 0
i = 0
while i < n:
	ans += a[i]
	j += 1
	if j == m:
		break
	wk1 = i
	while a[wk1] - a[i] <= 1:
		wk1 += 1
		if wk1 >= n:
			print(-1)
			quit()
	i = wk1
print(ans)


(n, k) = map(int, input().split())
a = list(input())
b = []
c = []
d = []
for i in a:
	b.append(ord(i) - 96)
count = 1
count2 = 0
count3 = 0
m = min(b)
mi = b.index(m)
d.append(a[mi])
count2 += m
a.pop(mi)
b.pop(mi)
m += 2
while count < k:
	try:
		mi = b.index(m)
		d.append(a[mi])
		count += 1
		count2 += m
		count3 = 0
		a.pop(mi)
		b.pop(mi)
		m += 2
	except:
		m += 1
		count3 += 1
	if count3 > 26:
		break
if count == k and count3 <= 26:
	print(count2)
else:
	print(-1)


(x, y) = map(int, input().split())
s = input()
s = list(s)
s.sort()
d = dict()
for i in range(97, 123):
	d[chr(i)] = i - 96
sum = 0
t = -1
c = 0
w = 0
for i in s:
	if d[i] - t >= 2:
		c += 1
		sum += d[i]
		t = d[i]
		if c == y:
			w = 1
			break
	else:
		continue
if w == 1:
	print(sum)
else:
	print('-1')


import sys
(n, k) = map(int, input().split())
s = input()
l = [x for x in s]
l.sort()
if k == 1:
	print(ord(l[0]) - ord('a') + 1)
	sys.exit()
ans = l[0]
t = ord(l[0])
i = 1
c = t - ord('a') + 1
for x in range(1, len(l)):
	if ord(l[x]) > t + 1:
		ans += l[x]
		i += 1
		t = ord(l[x])
		c += t - ord('a') + 1
	if i == k:
		break
if len(ans) < k:
	print(-1)
else:
	print(c)


from string import ascii_lowercase
x = list(ascii_lowercase)
x.insert(0, 0)
(n, k) = map(int, input().split())
s = list(input())
s.sort()
p = []
p.append(s[0])
for i in range(len(s)):
	if ord(s[i]) - ord(p[-1]) > 1:
		p.append(s[i])
	if len(p) == k:
		break
if len(p) == k:
	summ = 0
	for i in p:
		summ += x.index(i)
	print(summ)
else:
	print(-1)


s = input().split(' ')
(n, k) = [int(s[i]) for i in range(0, 2)]
s = input()
a = [s[i] for i in range(0, n)]
a.sort()
b = ['abcdefghijklmnopqrstuvwxyz'.find(a[i]) for i in range(0, n)]
b = [b[0] + 1] + [b[i] + 1 for i in range(1, n) if b[i] != b[i - 1]]

def f(i, c, w):
	w += b[i]
	c += 1
	if c == k:
		return w
	else:
		d = [f(i + j, c, w) for j in range(1, len(b) - i) if b[i + j] - 1 != b[i]]
		if len(d) > 0:
			return min(d)
		else:
			return 351
ar = [f(i, 0, 0) for i in range(0, len(b) - k + 1)]
if len(ar) > 0:
	res = min(ar)
else:
	res = 351
if res < 351:
	print(res)
else:
	print(-1)


(n, m) = map(int, input().split())
s = list(sorted(map(ord, input())))
jog = 0
x = 0
for i in s:
	if i - x > 1:
		jog += i - 96
		x = i
		m -= 1
	if m == 0:
		break
if m > 0:
	print(-1)
else:
	print(jog)


a = list(input().split(' '))
(n, k) = (int(a[0]), int(a[1]))
s = input()
s = sorted(s)
res_s = s[0]
for i in range(1, n):
	if ord(s[i]) - ord(res_s[-1]) > 1:
		res_s += s[i]
	if len(res_s) == k:
		break
if len(res_s) < k:
	print(-1)
else:
	ans = 0
	for i in range(k):
		ans += ord(res_s[i]) - ord('a') + 1
	print(ans)


(n, k) = map(int, input().split())
data = sorted((ord(c) - ord('a') + 1 for c in set(input())))
result = data[0]
prev = data[0]
cnt = 1
for i in range(1, len(data)):
	if cnt == k:
		break
	if data[i] == prev + 1:
		continue
	result += data[i]
	prev = data[i]
	cnt += 1
print(result if cnt == k else -1)


(n, k) = list(map(int, input().split()))
s = sorted(list(str(input())))
r = 0
c = 0
m = sorted(list(set(s)))
for i in range(len(m)):
	if i == 0:
		r += ord(m[i]) - 96
		c += 1
		t = m[i]
	elif ord(m[i]) - ord(t) != 1:
		r += ord(m[i]) - 96
		c += 1
		t = m[i]
	if c == k:
		break
print(-1 if c != k else r)


(n, m) = map(int, input().split())
st = [ord(x) - 96 for x in input()]
st.sort()
cnt = st[0]
i = 1
m = m - 1
prev = cnt
while m and i < n:
	if st[i] != prev + 1 and st[i] != prev:
		prev = st[i]
		cnt += st[i]
		m = m - 1
	i += 1
if m == 0:
	print(cnt)
else:
	print(-1)


(n, k) = input().split()
s = input()
d = {}
for i in range(26):
	d[chr(97 + i)] = i + 1
dp = {}
for j in s:
	dp[j] = d[j]
x = list(dp.values())
x.sort()
su = x[0]
t = x[0]
count = 1
for i in range(1, len(x)):
	if count < int(k):
		if x[i] - t >= 2:
			su = su + x[i]
			count = count + 1
			t = x[i]
	else:
		break
print(su if count == int(k) else -1)


(n, q) = input().split(' ')
n = int(n)
q = int(q)
ans = 0
r = list(input())
import string
letters = [i for i in string.ascii_lowercase]
count = 0
i = 0
while i < 26:
	if letters[i] in r:
		ans += ord(letters[i]) - ord('a') + 1
		i += 2
		count += 1
	else:
		i += 1
	if count == q:
		break
if count < q:
	print(-1)
else:
	print(ans)


from sys import stdin

def func(arr):
	return sum(list(map(lambda x: ord(x) - 96, arr)))
(n, k) = map(int, stdin.readline().split())
s = stdin.readline().strip()
ans = []
s = sorted(s)
for i in range(n - k + 1):
	arr = [s[i]]
	total = ord(s[i]) - ord('a') + 1
	count = 1
	m = i
	j = m + 1
	while j < n and count < k:
		if ord(s[j]) - ord(s[m]) >= 2:
			arr.append(s[j])
			count += 1
			total += ord(s[j]) + 1 - ord('a')
			m = j
			j = m + 1
		else:
			j += 1
	if len(arr) == k:
		ans.append(total)
	else:
		pass
if len(ans) == 0:
	print(-1)
else:
	print(min(ans))


(n, k) = map(int, input().split())
m = sorted(list(input()))
i = 0
ind = ord(m[0])
ans = ord(m[i]) - ord('a') + 1
try:
	for j in range(k - 1):
		while ord(m[i]) - ind <= 1:
			i += 1
		ind = ord(m[i])
		ans += ord(m[i]) - ord('a') + 1
	else:
		print(ans)
except IndexError:
	print(-1)


(n, k) = map(int, input().split())
x = list(input())
x.sort()
lastCh = x[0]
cnt = 1
val = ord(x[0]) - ord('a') + 1
for i in range(1, len(x)):
	if cnt == k:
		break
	if ord(x[i]) - ord(lastCh) > 1:
		lastCh = x[i]
		cnt += 1
		val += ord(x[i]) - ord('a') + 1
if cnt == k:
	print(val)
else:
	print(-1)


(n, k) = list(map(int, input().split()))
inst = sorted(input().strip())
start = 0
minc = ord(inst[start])
cur = start + 1
res = ord(inst[start]) - ord('a') + 1
for i in range(k - 1):
	while cur < n and ord(inst[cur]) - ord(inst[start]) < 2:
		cur += 1
	if cur < n:
		res += ord(inst[cur]) - ord('a') + 1
		start = cur
	else:
		print(-1)
		exit()
print(res)


(n, m) = map(int, input().split())
l = list(input())
l.sort()
r = ord('a') - 2
k = 0
a = 0
for i in l:
	if ord(i) >= r + 2:
		r = ord(i)
		a = a + ord(i) - ord('a') + 1
		k = k + 1
		if k >= m:
			print(a)
			break
else:
	print(-1)


from sys import stdin
from math import *
line = stdin.readline().rstrip().split()
n = int(line[0])
k = int(line[1])
letters = stdin.readline().rstrip().split()
available = [False] * 26
for c in letters[0]:
	available[ord(c) - ord('a')] = True
i = 0
cant = 0
accum = 0
while i < 26 and cant < k:
	if available[i]:
		cant += 1
		accum += i + 1
		i += 1
	i += 1
if cant < k:
	print(-1)
else:
	print(accum)


(n, m) = map(int, input().split())
m -= 1
a = list(input())
a.sort()
last = ord(a[0]) - 96
ves = last
if m != 0:
	for i in range(1, n):
		if ord(a[i]) - 96 - last >= 2:
			m -= 1
			last = ord(a[i]) - 96
			ves += last
			if m == 0:
				break
if m != 0:
	print('-1')
else:
	print(ves)


(n, k) = map(int, input().split())
l = list(input())
l.sort()
l1 = []
i = 0
u = 0
while i < n:
	if i == 0:
		l1.append(l[i])
		u = u + ord(l[i]) % 96
	if i > 0 and len(l1) < k:
		if ord(l[i]) - ord(l1[-1]) > 1:
			l1.append(l[i])
			u = u + ord(l[i]) % 96
	if len(l1) > k:
		break
	i = i + 1
if len(l1) == k:
	print(u)
else:
	print(-1)


(n, k) = list(map(int, input().split()))
all_parts = dict([(j, i + 1) for (i, j) in enumerate(list('abcdefghijklmnopqrstuvwxyz'))])
av_parts = sorted(list(input()))
rocket = []
for step in av_parts:
	if len(rocket) == k:
		break
	elif len(rocket) == 0:
		rocket.append(step)
	elif all_parts[rocket[-1]] < all_parts[step] - 1:
		rocket.append(step)
if len(rocket) < k:
	print(-1)
else:
	print(sum(list(map(lambda x: all_parts[x], rocket))))


(a, b) = map(int, input().strip().split()[:2])
l = list(input()[:a])
c = -1
p = []
for x in range(a):
	k = min(l)
	if abs(c - ord(k)) >= 2:
		c = ord(k)
		p.append(ord(k))
		l.remove(k)
	else:
		l.remove(k)
if len(p) >= b:
	p = p[:b]
	print(sum(p) - 96 * len(p))
else:
	print(-1)


(n, k) = map(int, input().split())
b = []
s = input()
for j in s:
	b.append(j)
b.sort()
r = ord(b[0]) - 96
p = 1
j = 1
q = 0
while j < n:
	if p == k:
		break
	if ord(b[j]) - ord(b[q]) > 1:
		p += 1
		r += ord(b[j]) - 96
		q = j
	j += 1
if p == k:
	print(r)
else:
	print(-1)


(n, k) = input().strip().split()
(n, k) = (int(n), int(k))
s = input().strip()
s = sorted([ord(i) - 96 for i in s])
try:
	wt = 0
	last = None
	while k:
		if last:
			ll = s.pop(0)
			if ll - 1 > last:
				k -= 1
				last = ll
				wt += last
		else:
			last = s.pop(0)
			k -= 1
			wt += last
	print(wt)
except IndexError:
	print(-1)


entrada = input()
entrada = entrada.split()
n = int(entrada[0])
k = int(entrada[-1])
s = input()
s = sorted(s)
ant = 0
r = 0
for letra in s:
	if ord(letra) - ant > 1:
		r += ord(letra) - 96
		ant = ord(letra)
		k -= 1
		if k == 0:
			break
if k == 0:
	print(r)
else:
	print(-1)


(n, k) = [int(x) for x in input().split()]
s = input()
s = list(set([ord(x) - 96 for x in s]))
s.sort()
if k > 13:
	print(-1)
elif k == 1 and len(s) > 0:
	print(s[0])
else:
	min = sum(s)
	t = False
	for i in range(len(s)):
		j = i + 1
		l = 1
		w = s[i]
		m = i
		for j in range(i + 1, len(s)):
			if s[j] - 1 > s[m]:
				m = j
				w += s[j]
				l += 1
				if l == k:
					if min >= w:
						t = True
						min = w
					break
	if t:
		print(min)
	else:
		print(-1)


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 main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

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

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l

def sq(a, target, arr=[]):
	s = sum(arr)
	if s == target:
		return arr
	if s >= target:
		return
	for i in range(len(a)):
		n = a[i]
		remaining = a[i + 1:]
		ans = sq(remaining, target, arr + [n])
		if ans:
			return ans

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

def nCr(n, r):
	f = math.factorial
	return f(n) // f(r) // f(n - r)
mod = int(1000000000.0) + 7

def ssinp():
	return input()

def iinp():
	return int(input())

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

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

def p(xyz):
	print(xyz)

def p2(a, b):
	print(a, b)
import math
(n, k) = nninp()
s = stl(ssinp())
s.sort()
s.append('a')
curr = s[0]
ans = ord(s[0]) - 96
k = k - 1
for i in range(1, n + 1):
	if k <= 0:
		print(ans)
		exit()
	if ord(curr) + 2 <= ord(s[i]):
		ans += ord(s[i]) - 96
		k -= 1
		curr = s[i]
print(-1)


def fnx(a, b):
	if b - a > 1:
		return True
	return False
(n, k) = [int(i) for i in input().split(' ')]
s = str(input())
d = [ord(i) - 96 for i in s]
d.sort()
e = d[0]
su = e
t = 1
for i in range(1, n):
	if t >= k:
		break
	if fnx(e, d[i]):
		su += d[i]
		e = d[i]
		t += 1
if t != k:
	print(-1)
else:
	print(su)


(n, k) = map(int, input().split())
s = sorted(list(map(lambda x: ord(x) - 96, list(input()))))
p = -1
c = 0
v = 0
for i in range(n):
	if c == k:
		break
	if s[i] - p > 1:
		p = s[i]
		c += 1
		v += s[i]
if c < k:
	print(-1)
else:
	print(v)


(n, k) = [int(i) for i in input().split()]
rocket = [ord(i) - 96 for i in list(input())]
rocket.sort()
(sum, i) = (0, 1)
prev = rocket[0]
sum += rocket[0]
k -= 1
while k > 0 and i < n:
	if rocket[i] - prev > 1:
		sum += rocket[i]
		prev = rocket[i]
		k -= 1
	i += 1
if k == 0:
	print(sum)
else:
	print('-1')


[n, k] = map(int, input().split())
l = list(input())
l.sort()
ans = ord(l[0]) - ord('a') + 1
last = l[0]
cnt = 1
for i in range(1, len(l)):
	if cnt == k:
		break
	if ord(l[i]) - ord(last) > 1:
		last = l[i]
		ans += ord(last) - ord('a') + 1
		cnt += 1
	if cnt == k:
		break
if cnt == k:
	print(ans)
else:
	print('-1')


(n, p) = [int(x) for x in input().split()]
a = []
s = input()
for i in s:
	a.append(i)
a.sort()
ans = 0
k = ''
k = a[0]
ans += ord(k) - ord('a') + 1
p -= 1
for i in range(1, len(a)):
	if p == 0:
		break
	if ord(a[i]) - ord(k) >= 2:
		k = a[i]
		ans += ord(k) - ord('a') + 1
		p -= 1
if p != 0:
	print(-1)
else:
	print(ans)


M = lambda : list(map(int, input().split()))
(n, k) = M()
t = []
for code in map(ord, sorted(input())):
	t.append(code - 96)
h = 0
sm = 0
cnt = 0
j = sorted(set(t))
for i in j:
	if i != h:
		sm += i
		cnt += 1
		h = i + 1
		if cnt == k:
			break
if cnt >= k:
	print(sm)
else:
	print(-1)


(n, k) = map(int, input().split())
weights = sorted([x - ord('a') + 1 for x in map(ord, list(input()))])
num = 0
weight = 0
lastw = -2
for (i, w) in enumerate(weights):
	if w - lastw < 2:
		continue
	weight += w
	num += 1
	lastw = w
	if num == k:
		break
print(weight if num == k else -1)


(n, k) = map(int, input().split())
a = sorted(list(set(input())))
cnt = 0
m = 0
flag = True
for i in range(len(a)):
	if cnt == k:
		break
	if i - 1 >= 0 and flag:
		if a[i - 1] == chr(ord(a[i]) - 1):
			flag = False
			continue
	m += ord(a[i]) - ord('a') + 1
	cnt += 1
	flag = True
if cnt < k:
	print(-1)
else:
	print(m)


from string import ascii_lowercase
tmp = {letter: index for (index, letter) in enumerate(ascii_lowercase, start=1)}
(n, k) = list(map(int, input().split()))
stages = list(map(lambda x: tmp[x], input()))
stages = sorted(stages)
t = [stages[0]]
stages = stages[1:]
flag = 0
for i in range(k - 1):
	stages = list(filter(lambda x: x - t[-1] > 1, stages))
	if len(stages) == 0:
		print(-1)
		flag = 1
		break
	t.append(stages[0])
if not flag:
	print(sum(t))


(n, k) = map(int, input().split())
s = input()
s = ''.join(sorted(s))
l = s[0]
i = 0
flag = True
while len(l) != k:
	if i >= n:
		flag = False
		break
	if ord(l[-1]) + 1 < ord(s[i]):
		l = l + s[i]
	i += 1
if flag:
	print(sum((ord(x) for x in l)) - 96 * k)
else:
	print(-1)


(n, m) = map(int, input().split())
s = tuple(sorted(input()))
k = True
for i in range(n - m + 1):
	ans = ord(s[i]) - 96
	c = 1
	k1 = i
	for j in range(i + 1, n):
		if ord(s[j]) - ord(s[k1]) > 1 and c <= m:
			ans += ord(s[j]) - 96
			c += 1
			k1 = j
		if c == m:
			print(ans)
			k = False
			break
	if not k:
		break
if k and len(s) != 1 and (m != 1):
	print(-1)
elif k and m == 1:
	print(ord(s[0]) - 96)


if 1:
	(n, k) = map(int, input().split())
	s = [i for i in input()]
	s.sort()
	c = ord(s[0]) - 96
	k -= 1
	x = s[0]
	for i in range(n):
		if k == 0:
			break
		if ord(s[i]) >= ord(x[-1]) + 2:
			x += s[i]
			c += ord(s[i]) - 96
			k -= 1
	if k:
		print(-1)
	else:
		print(c)


f = lambda : map(int, input().split())
(n, k) = f()
s = sorted(list(set(input())))
vs = s[0]
for i in range(1, len(s)):
	if ord(s[i]) - ord(vs[-1]) >= 2:
		vs = vs + s[i]
v = 0
if len(vs) >= k:
	for i in vs[:k]:
		v += ord(i) - ord('a') + 1
	print(v)
else:
	print(-1)


from sys import stdin

def iinput():
	return int(stdin.readline())

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

def linput():
	return list(map(int, stdin.readline().split()))
(n, k) = minput()
s = input()
s = sorted(s)
w = ord(s[0]) - 96
p = s[0]
i = 1
k -= 1
while k and i < n:
	if ord(s[i]) - ord(p) >= 2:
		w += ord(s[i]) - 96
		p = s[i]
		k -= 1
	i += 1
if k:
	print(-1)
else:
	print(w)


from collections import Counter, defaultdict, deque
read = lambda : list(map(int, input().split()))
getinfo = lambda grid: print(list(map(print, grid)))
p = lambda x: print(x, end=' ')
mod = 10 ** 9 + 7
inf = float('inf')
(n, k) = read()
s = list(input())
s.sort()
res = s[0]
for i in range(1, len(s)):
	if len(res) == k:
		break
	if ord(s[i]) - ord(res[-1]) >= 2:
		res += s[i]
if len(res) < k:
	print(-1)
else:
	cost = 0
	for e in res:
		cost += ord(e) - ord('a') + 1
	print(cost)


(pocPisNaPouz, pocPis) = list(map(int, input().split(' ')))
pisNaPouz = sorted(input())
vysledok = 0
poslPis = 95
pocitPis = 0
for i in range(pocPisNaPouz):
	if ord(pisNaPouz[i]) - poslPis <= 1:
		pass
	else:
		vysledok += ord(pisNaPouz[i]) - 96
		poslPis = ord(pisNaPouz[i])
		pocitPis += 1
		if pocitPis == pocPis:
			break
if pocitPis == pocPis:
	print(vysledok)
else:
	print(-1)


(n, k) = map(int, input().split())
s = input()
b = ''.join(sorted(s))
m = ''
a = b[0]
m = b[0]
for i in range(k - 1):
	for j in b:
		if ord(j) - ord(a) > 1:
			m += j
			a = j
			break
if len(m) != k:
	print('-1')
else:
	o = 0
	for h in m:
		o += ord(h) - 96
	print(o)


(n, m) = map(int, input().split())
x = list(set((ord(i) - ord('a') + 1 for i in input())))
ji = 1
flag = x[0]
ans = x[0]
x.sort()
for i in range(1, len(x)):
	if ji >= m:
		break
	if x[i] - flag > 1:
		ji += 1
		flag = x[i]
		ans += x[i]
	if ji >= m:
		break
if ji >= m:
	print(ans)
else:
	print(-1)


(n, k) = map(int, input().split())
a = list(input())
l = list(map(ord, a))
l.sort()
i = 0
p = 0
x = []
while i < n and len(x) < k:
	if l[i] - p > 1:
		x.append(l[i])
		p = l[i]
	i += 1
if len(x) == k:
	print(sum(x) - 96 * k)
else:
	print(-1)


arr = input()
arr = arr.split(' ')
n = int(arr[0])
k = int(arr[1])
letters = input()
letters = list(letters)
weight = []
total = 0
for i in range(0, n):
	weight.append(ord(letters[i]) - 96)
weight = sorted(weight)
x = 0
while x < n - 1:
	if x < len(weight) - 1:
		if weight[x + 1] - weight[x] < 2:
			weight.pop(x + 1)
			x = x - 1
	x = x + 1
for y in range(0, len(weight) - k):
	weight.pop()
for x in range(0, len(weight)):
	total = total + weight[x]
if len(weight) < k:
	total = -1
print(total)


l1 = [int(x) for x in input().split()]
(n, k) = (l1[0], l1[1])
alfie = 'abcdefghijklmnopqrstuvwxyz'
l2 = list(input())
cools = 0
i = 0
weight = 0
cool = 0
while i < 26 and cools < k:
	if alfie[i] in l2:
		cools += 1
		weight += i + 1
		i += 1
	i += 1
if cools >= k:
	print(weight)
else:
	print(-1)


(n, k) = input().split()
(n, k) = (int(n), int(k))
s = str(input())
d = sorted(list(set(s)))
index_c = ord(d[0]) - 96
lst = [d[0]]
count = 0
for i in range(1, len(d)):
	if count == k - 1:
		break
	index1 = ord(d[i]) - 96
	if index1 - index_c == 1:
		continue
	else:
		lst.append(d[i])
		index_c = index1
		count += 1
ans = 0
if k > 1 and len(lst) == 1:
	ans = -1
elif len(lst) < k:
	ans = -1
else:
	for i in lst:
		ans += ord(i) - 96
print(ans)


(m, n) = map(int, input().split())
(num, pre) = (0, 0)
s = list(input())
s = sorted(s)
j = 0
for i in s:
	if ord(i) - pre > 1:
		num += ord(i) - 96
		pre = ord(i)
		j += 1
	if j == n:
		break
if j == n:
	print(num)
else:
	print(-1)


import sys
(n, k) = map(int, input().split())
s = input()
r = []
for i in s:
	r.append(i)
r.sort()
pointer = 1
ans = ord(r[0]) - ord('a') + 1
last = ord(r[0])
for i in range(k - 1):
	while pointer < n and ord(r[pointer]) <= last + 1:
		pointer += 1
	if pointer == n:
		print(-1)
		sys.exit()
	ans += ord(r[pointer]) - ord('a') + 1
	last = ord(r[pointer])
print(ans)


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

def cost(c):
	return ord(c) - ord('a') + 1
curr = 0
total = cost(s[curr])
count = 1
for i in range(1, n):
	if count == k:
		break
	if cost(s[i]) - cost(s[curr]) >= 2:
		total += cost(s[i])
		count += 1
		curr = i
if count == k:
	print(total)
else:
	print(-1)


import string
ref = {b: a for (a, b) in enumerate(string.ascii_lowercase, 1)}
(n, k) = list(map(int, input().split()))
s = input()
num = []
for x in sorted(s):
	num.append(ref[x])
base = [num[0]]
for y in num:
	if y - base[-1] > 1 and len(base) < k:
		base.append(y)
	if len(base) == k:
		break
if len(base) < k:
	print(-1)
else:
	print(sum(base))


s1 = input()
s1 = s1.split()
for i in range(2):
	s1[i] = int(s1[i])
x = 0
u = 0
count = 0
s2 = []
m = input()
l = list(m)
for i in range(len(l)):
	if l[i] not in s2:
		s2.append(l[i])
s2.sort()
M = []
i = 0
while i < len(s2):
	if count == s1[1]:
		break
	elif i == 0:
		x = x + ord(s2[i]) - 96
		count = count + 1
		i = i + 1
	elif ord(s2[i]) - ord(s2[i - 1]) < 2:
		del s2[i]
	elif ord(s2[i]) - ord(s2[i - 1]) >= 2:
		x = x + ord(s2[i]) - 96
		count = count + 1
		i = i + 1
if count == s1[1]:
	print(x)
else:
	print(-1)


t = [0] * 30
(n, k) = map(int, input().split())
s = input()
l = len(s)
for i in s:
	t[ord(i) - ord('a')] = 1
ans = 0
mat = 0
cnt = 0
while cnt < 26:
	if t[cnt] == 1:
		ans += cnt + 1
		cnt += 1
		mat += 1
	if mat == k:
		break
	cnt += 1
if mat < k:
	print(-1)
else:
	print(ans)


(n, k) = list(map(int, input().strip().split()))
a = str(input())
let = []
for j in range(n):
	if a[j] not in let:
		let.append(a[j])
let.sort()
take = [ord(x) - 96 for x in let]
c = take[0]
co = 1
last = take[0]
for i in range(1, len(take)):
	if co < k and take[i] > last + 1:
		co += 1
		last = take[i]
		c += last
if co < k:
	print(-1)
else:
	print(c)


(n, k) = [int(x) for x in input().split()]
s = sorted(input())
ans = []
ss = 0
for a in s:
	num = ord(a) - ord('a') + 1
	if len(ans) == 0:
		ans.append(num)
		ss = ss + num
	elif len(ans) >= k:
		break
	elif num - ans[-1] > 1:
		ans.append(num)
		ss = ss + num
if len(ans) < k:
	print('-1')
else:
	print(ss)


(n, k) = list(map(int, input().split()))
s = list(input())
s.sort()
w = 0
p = []
for i in range(n):
	if len(p) == 0 or ord(p[-1]) + 1 < ord(s[i]):
		p.append(s[i])
		w += ord(s[i]) - 97 + 1
	if len(p) == k:
		break
if len(p) == k:
	print(w)
else:
	print(-1)


(x, y) = input().split()
x = int(x)
y = int(y)
chuoi = input()
tl = []
rs = 0
for i in chuoi:
	tl.append(i)
tl.sort()
for i in range(x):
	temp = ord(tl[i]) - 96
	doi = 1
	truoc = tl[i]
	for j in range(i + 1, x):
		if ord(tl[j]) - ord(truoc) > 1:
			if doi == y:
				break
			temp += ord(tl[j]) - 96
			truoc = tl[j]
			doi += 1
	if (rs == 0 or rs > temp) and doi == y:
		rs = temp
print(-1) if rs == 0 else print(rs)


(n, k) = map(int, input().split())
l = []
s = input()
l[:0] = s
l.sort()
last = chr(ord('a') - 2)
ans = len = 0
for i in range(n):
	z = chr(ord(last) + 2)
	if l[i] >= z:
		last = l[i]
		ans += ord(l[i]) - ord('a') + 1
		len += 1
		if len >= k:
			print(ans)
			exit()
print(-1)


(n, k) = map(int, input().split())
s = input()
a = [0] * 26
for i in s:
	a[ord(i) - ord('a')] += 1
s = sorted(s)
last_pic = s[0]
current = s[0]
ans = 0
ans += ord(s[0]) - ord('a') + 1
count = 1
for i in range(1, len(s)):
	if count >= k:
		break
	if ord(s[i]) - ord(last_pic) > 1:
		count += 1
		last_pic = s[i]
		ans += ord(s[i]) - ord('a') + 1
if n < k or count != k:
	print('-1')
else:
	print(ans)


(n, k) = (int(x) for x in input().split())
s = input()
alph = 'abcdefghijklmnopqrstuvwxyz'
s = sorted(s)
ans = [s[0]]
i = 1
count = 1
while i < n:
	if count == k:
		break
	str = alph[alph.index(ans[-1]) + 2:]
	if s[i] in str:
		ans.append(s[i])
		count += 1
	i += 1
if count < k:
	print(-1)
else:
	sum = 0
	for i in ans:
		sum += alph.index(i) + 1
	print(sum)


(n, k) = map(int, input().split())
s = [ord(c) - 96 for c in input()]
s.sort()
last = -1
cost = num = i = 0
if k == 1:
	print(s[i])
else:
	while i < n:
		if s[i] >= last + 2:
			last = s[i]
			cost += s[i]
			num += 1
			if num >= k:
				print(cost)
				break
		i += 1
	else:
		print(-1)


(n, m) = map(int, input().split())
a = input()
a = ''.join(set(a))
a = list(a)
a.sort()
b = ord(a[0])
count = b - 96
m -= 1
if m > 0:
	for i in range(1, len(a)):
		if ord(a[i]) - b >= 2:
			b = ord(a[i])
			count = count + (b - 96)
			m -= 1
			if m == 0:
				break
if m > 0:
	print(-1)
else:
	print(count)


import os
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
test_count = 1
if debug:
	test_count = inp()
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	(n, k) = invr()
	a = list(insr())
	a.sort()
	ans = 0
	last = -1
	for i in range(n):
		x = ord(a[i])
		if x > last + 1:
			ans += x - ord('a') + 1
			k -= 1
			last = x
		if k == 0:
			break
	if k != 0:
		print(-1)
	else:
		print(ans)