25 lines
502 B
Python
25 lines
502 B
Python
|
def weight(c):
|
||
|
return ord(c)-ord('a')+1
|
||
|
|
||
|
def main():
|
||
|
n, k, = [int(i) for i in input().split()]
|
||
|
string = [i for i in input()]
|
||
|
string.sort(key=weight)
|
||
|
|
||
|
total_weight = 0
|
||
|
last_weight = -1
|
||
|
curr = 0
|
||
|
for i in string:
|
||
|
if curr == k:
|
||
|
break
|
||
|
if weight(i) > last_weight+1:
|
||
|
total_weight += weight(i)
|
||
|
last_weight = weight(i)
|
||
|
curr += 1
|
||
|
if curr == k:
|
||
|
print(total_weight)
|
||
|
else:
|
||
|
print(-1)
|
||
|
|
||
|
|
||
|
main()
|