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.

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.

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

NoteIn 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.

#include <iostream>
#include <string>
using namespace std;
int n, k;
string s;
int alphabet[27];
int main() {
	cin >> n >> k;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		alphabet[(s[i] - 97)]++;
	}
	int curv = 0;
	int sum = 0;
	while (curv < 26 && k > 0) {
		if (alphabet[curv]) {
			sum += (curv + 1);
			curv += 2;
			k--;
		}
		else {
			curv++;
		}
	}
	if (k != 0) {
		cout << -1 << endl;
	}
	else cout << sum << endl;
}

#include <iostream>
using namespace std;

int main() {
    int n, k,sum,con;
    int min= 100000;
     cin >> n >> k;
     char c;
     int a[27]{0};
     for(int i=1;i<=n;i++)
     {
         cin >> c;
         a[int(c)-96]++;
     }

     if (k==1)
     {for(int i=1;i<=26;i++)
     if(a[i]!=0) {cout << i ;break;}}

     else
     {
        for(int i=1;i<=26;i++)
        {
            if (a[i]!=0)
            {
                sum=i;con=1;
                for(int j=i+2;j<=26;j++)
                {
                    if(a[j]!=0)
                    {sum+=j;con++;j++;}
                    if(con==k) {min=(min<sum)? min : sum;break;}
                }

            }

        }
        if(min!=100000) cout << min;
        else cout <<-1;

     }
	return 0;
}

/*input
7 4
problem

*/
#include<bits/stdc++.h>
using namespace std;
typedef std::vector<int> vi;
typedef std::vector<vi> vii;
typedef std::vector<bool> vb;
typedef long long ll;
typedef std::vector<ll> vl;
typedef std::vector<vl> vll;
typedef std::pair<int, int> ii;
typedef std::vector<vb> vbb;
typedef std::vector<ii> vp;
typedef std::vector<vp> vpp;
typedef std::string str;
typedef std::vector<str> vs;
#define x first
#define y second
const int INF = (int)1e9;
const ll INFl = (ll)1e18;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int N, k;
	cin >> N >> k;
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	int count = 0;
	int sum = 0;
	int curr = -2;
	for (int i = 0; i < N && count != k; ++i)
	{
		if(s[i] - 'a' - 1 > curr){
			sum += s[i] - 'a' + 1;
			count++;
			curr = s[i] - 'a';
		}
	}
	return !printf("%d\n", (count == k) ? sum: -1);
}

#include <bits/stdc++.h>
#define li long long int
using namespace std;
li arr[1000005]={0};
int main()
{
li n,k;
cin>>n>>k;
string s;
cin>>s;
s+=" ";
sort(s.begin(),s.end());
li p=1,l=0,ans=0;
while(k && p<=n)
{
    if(s[p]-s[l]>=2)
    {
        ans+=s[p]-'a'+1;
        k--;
        l=p;
    }
    p++;
}
if(!k)
cout<<ans<<endl;
else
cout<<"-1"<<endl;
}

/*
....................................................................................
RRRRRRRRRR        EEEEEEEEEEE           ZZZZZZZZZZZZZ           K K        K K     .
RRRRRRRRRR        EEEEEEEEEEE           ZZZZZZZZZZZZZ           K K       K K      .
R R     R R       E E     E E                     Z Z           K K      K K       .
R R     R R       E E     E E                    Z Z            K K     K K        .
R R     R R       E E     E E                   Z Z             K K    K K         .
R R    R R        E E     E E                  Z Z              K K   K K          .
RRRRRRRR          EEEEEEEEEEE                 Z Z               K KKKKKK           .
RRRRRRRR          EEEEEEEEEEE                Z Z                K KKKKKK           .
R R R R           E E                       Z Z                 K K   K K          .
R R  R R          E E                      Z Z                  K K    K K         .
R R   R R         E E                     Z Z                   K K     K K        .
R R    R R        EEEEEEEEEEE            ZZZZZZZZZZZ            K K      K K       .
R R     R R       EEEEEEEEEEE           ZZZZZZZZZZZZ            K K       K K      .
....................................................................................
*/

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<iomanip>
#include<cmath>
#include <utility>
#include <numeric>
#include<complex>
#include<sstream>
#include <functional>
#include<valarray>
#define ln cout<<endl;
#define vll vector<long long int>
#define vi vector<int>
#define vc vector<char>
#define vst vector<string>
#define sti set<int>
#define sz size()
#define lli long long int
using namespace std;
string tostring(double n){
	double m=n;
	string x;
    stringstream ss;
    ss<<m;
    ss>>x;
 return x;
}

lli f(lli n){
	lli  sum=(n*(1+n))/2;
	return sum;
}
bool in(string s1,string s2)
{
	string sub,ns;bool f=false;
	if(s1.size()<s2.size()){sub=s1;ns=s2;}
	else {sub=s2;ns=s1;}
	for (int i = 0; i < ns.size();i++ )
	{
		if(sub[0]==ns[i])
		{
			bool f=true;
			for (int  j= 0,k=i;j<sub.size();)
			{
				if(sub[j]==ns[k]){k++;j++;}
				else{f=false ;break;};
			}
			if(f)return f;
		}
	}
	return f;
}

int main()
{
	int n,k,a[55];
	cin>>n>>k;
	string s,x="abcdefghijklmnopqrstuvwxyz";//abdxy
	cin>>s;
	vi v;
	sort(s.begin(),s.end());
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 26; j++)
		{
			if(s[i]==x[j]){a[i]=j+1;break;}
		}
	}
	if(k==1){cout<<a[0];return 0;}
	int c=1,sum=a[0];
	v.push_back(a[0]);
	for (int i = 1; i<n; i++)
	{
		if(a[i]-v[c-1]>1){c++;sum+=a[i];
		v.push_back(a[i]);}
		if(c==k)break;
	}
	if(c!=k)cout<<-1;
	else cout<<sum;
	return 0;
}

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    int ans=0,d=0;
    int A[30];
    for(int i=0;i<30;i++)A[i]=0;
    for(int i=0;i<s.length();i++)
        A[s[i]-'a']=1;
    if(k>13)
      cout<<-1<<endl;
    else
      {
      	int prev=-2;
      	for(int i=0;i<26;i++)
      	   {
      	     if(A[i]==1&&prev<i-1)
			    {
			    	d++;
			    	ans+=(i+1);
			    	prev=i;
				}
			 if(d==k)
			   {
			   	cout<<ans<<endl;
			   	return 0;
				   }
		   }
		   cout<<-1<<endl;
	  }

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int a[10005];
int main()
{
    string s;
    int n,m;
    cin >> n>>m>>s;
    int p = 0;
    if(s.size() <m) {printf("-1\n");return 0;}
    for(int i = 0; i < s.size(); i++){
        a[p++] =(int)(s[i] - 'a' + 1);
    }

    sort(a, a+p);
   /* for(int i = 0; i < p; i++){
        printf("%d ",a[i]);
    }*/
    int sum = 0;
    sum += a[0];
    int flag = 1;
    int x = 0;
    for(int i = 1 ; i < p; i++){
        if(flag == m) break;
        if(a[i] > a[x] + 1){
            sum += a[i];
            flag++;
            x = i;
        }
        else continue;

    }
    if(flag < m) printf("-1\n");
    else printf("%d\n",sum);
}

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>

using namespace std;

char S[64];

int main(){
	int n, k, tmp;
	scanf("%d %d ", &n, &k);
	gets(S);
	int t=strlen(S);
	for(int i=0; i<t-1; i++)
		for(int j=i+1; j<t; j++){
			if(S[i]>S[j]){

			tmp=S[i];
			S[i]=S[j];
			S[j]=tmp;
			}
		}
	int p=0, g=0, sum=0, f=0;
	while(p<t && g<k){
		if((S[p]-S[f])>1 || p==0){
			sum=sum+S[p]-'a'+1;
			f=p;
			g++;
		}
		p++;
	}

	if(g!=k)
		cout<<"-1";
	else
		cout<<sum;
	return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define  pb push_back
#define  pob pop_back
#define W while
#define fn(i,x) for(int i=0;i<x;i++)
#define fs(i,s,x) for(int i=s;i<x;i++)
#define fr(i,x) for(int i=x;i>=0;i--)
#define fit(it,s) for(auto it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 1000000007
#define MAX 100005
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    ll n,k;
    cin>>n>>k;

    char g[n];
    fn(i,n) cin>>g[i];

    ll ans=INT_MAX;

    sort(g,g+n);
    //cout<<g<<" ";

    for(int i=0;i<n;i++)
    {
    	ll s=g[i]-'a'+1;
        string h;
        h.pb(g[i]);
        if(h.size()==k) { ans=min(ans,s); break; }

    	for(int j=i+1;j<n;j++)
    	{
    		        // cout<<h<<" ";
    		   		if(h.size()==k) { ans=min(ans,s); break; }
    		if(g[j]<=h[h.size()-1]+1)
    			continue;
    		else {
    			s+=g[j]-'a'+1;
    			h.pb(g[j]);
    			//break;
    		}
    		if(h.size()==k) { ans=min(ans,s); break; }
    	//	cout<<"\n";

    	}
    	//if(m==k)

    }
    if(ans==INT_MAX) cout<<"-1";
    else cout<<ans;

    return 0;

}

#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long

int main()
{
	int n,m,i,j,k,x,t,a[55],sum=0;
	string s;
	cin>>n>>m;
	getchar();
	cin>>s;
	for(i=0; i<n; i++)
		a[i]=s[i]-'a'+1;
	sort(a,a+n);
	j=1;
	for(i=1; i<n; i++)
		if(a[i]!=a[i-1])
			j++;
	/*cout<<j<<endl;
	for(i=0;i<n;i++)
	cout<<a[i]<<" ";*/
	if(j<m)
	{
		cout<<"-1"<<endl;
		return 0;
	}
	sum+=a[0];
	m--;
	t=a[0];
	for(i=1; i<n; i++)
	{
		if(m==0)
			break;
		if(a[i]-t>1)
		{
			t=a[i];
			sum+=a[i];
			m--;
		}
	}
	if(m==0)
		cout<<sum<<endl;
	else
		cout<<"-1"<<endl;
	return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	int n,m,sum,min,len;
	char p;
	while(scanf("%d%d",&n,&m)!=EOF){
		len=sum=0;
		min=99999;
		string str;
		cin>>str;
		sort(str.begin(),str.end());
		//cout<<str<<endl;
		if(1==m){
			min=str[0]-'a'+1;
		}
		else{
		    for(int i=0;i<str.size();i++){
			    p=str[i];
			    len=1;
			    sum=p-'a'+1;
			    for(int j=i+1;j<str.size();j++){
			    	if(str[j]-p>=2){
					    len++,sum+=str[j]-'a'+1;
					    p=str[j];
					   // cout<<"p :"<<str[j]<<endl;
					    //cout<<"len :"<<len<<endl;
					    if(len==m){
						    if(min>sum) min=sum;
						    break;
					    }
				    }
			   }
		   }
	   }
		if(min!=99999) printf("%d\n",min);
		else printf("-1\n");
	}
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	char str[n];
	scanf("%s", str);
	sort(str, str+n);
	// printf("%s", str);
	int p = 0, sum = 0, c = 1;
	sum = (int)(str[p]-'a')+1;
	// cout << sum << endl;
	// printf("%d", str[1]-str[0]);

	if(n==1){cout << sum << endl;}
	else
	{
		for(int i=1;i<n;i++)
		{
			if(c == m){break;}
			if(str[i] - str[p] >= 2){sum = sum + (int)(str[i] - 'a')+1;p = i;c++;}
			// cout << sum << endl;
		}
		if(c == m){cout << sum << endl;}
		else{cout << -1 << endl;}
	}
}

#include<bits/stdc++.h>
#define MAXN 55

using namespace std;

inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
char ch[MAXN];
int n,k;
int now,tot,ans;
int main(){
    n=read();k=read();
    for(int i=1;i<=n;++i){
        ch[i]=getchar();
        while(ch[i]<'a'||ch[i]>'z')ch[i]=getchar();
    }
    sort(ch+1,ch+n+1);
    ch[n+1]='z';
    for(int i=1;i<=n;++i){
        while(ch[i]<ch[now]+2&&i<=n)i++;
        if(i>n)break;
        ans+=ch[i]-'a'+1;tot++;now=i;
        if(tot==k)break;
    }
    if(tot==k)printf("%d\n",ans);
    else printf("-1\n");
    return 0;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <set>
using namespace std;
typedef long long ll;

const int maxn = 55;
int n,m;
int a[maxn];
char s[55];

int main(){
	while(cin>>n>>m){
		memset(a,0,sizeof(a));
		memset(s,0,sizeof(s));
		cin>>s;
		for(int i=0;i<n;i++){
			a[s[i]-'a'+1]++;
		}
		int l=-1,r=-1;
		int ans=0,num=0;
		int flag=1;
		int f=0;
		int pos;
		while(flag){
		//	cout<<l<<endl;
			l+=2;
			while(!a[l]&&l<30) l++;
			if(l>=27){
				f=1;
				break;
			}
			a[l]--;
			ans+=l;
			num++;

			//cout<<"  "<<num<<"  "<<(char)(l+'a'-1)<<"   "<<r<<"   "<<ans<<endl;

			if(f){
				f=1;
				break;
			}
			if(num==m){
				f=0;
				break;
			}

			l+=2;
			while(!a[l]&&l<30) l++;
			if(l>=27){
				f=1;
				break;
			}
			a[l]--;
			ans+=l;
			num++;
		//	cout<<"  "<<num<<"  "<<(char)(l+'a'-1)<<"   "<<r<<"   "<<ans<<endl;
			/*
			cout<<"  "<<num<<"  "<<(char)(l+'a'-1)<<"   "<<r<<"   "<<ans<<endl;
			if(num==m){
				f=0;
				break;
			}
			for(int i=l+2;i<27;i++){
				if(a[i]){
					a[i]--;
					num++;
					ans+=i;
					r=i;
					f=0;
					l=i;
					break;
				}
			}
			cout<<"  "<<num<<"  "<<(char)(l+'a'-1)<<"   "<<r<<ans<<endl;
			*/
			if(f){
				f=1;
				break;
			}
			if(num==m){
				f=0;
				break;
			}
		}
		if(f)cout<<-1<<endl;
		else cout<<ans<<endl;
	}
	return 0;
}

#include <iostream>
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	char arr[n],i,j=0;
	for(i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	sort(arr,arr+n);
	if(k==1)
	{
		cout<<arr[0]-96<<endl;
		exit(0);
	}
	int p=1;
	int max=arr[0]-'a'+1,x;
	for(i=1;i<n;i++)
	{
		x=(arr[i]-arr[j]);
		if(x>1)
		{
			max+=(arr[i]-'a'+1);
			j=i;
			p++;
		}
		if(p==k)
			break;
	}
	if(p!=k)
		cout<<-1<<endl;
	else
		cout<<max<<endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    char last='a'-2;
    int ans=0;
    int len=0;
    for(int i=0;i<n;i++)
        if(s[i]>=last+2)
        {
            last=s[i];
            ans+=s[i]-'a'+1;
            len++;
            if(len>=k)
                cout<<ans,exit(0);
        }
    cout<<-1;
}

#include<bits/stdc++.h>
using namespace std;

void funct(string str,int k,int n)
{
//cout<<str<<"\n";
            int j=0;
    int sum=0;
    for(int i=0;i<k;i++)
    {
        if(j>=n)
        {
            sum=-1;
            break;
        }
        sum=sum+int(str[j])-96;
         while(str[j]==str[j+1])
        {
            j=j+1;

        }
        if(str[j+1]==(str[j]+1))
        {
               j=j+2;
                        while(str[j]==str[j-1])
        {
            j=j+1;

        }

        }
        else
            j=j+1;

         while(str[j]==str[j+1])
        {
            j=j+1;

        }

 //cout<<sum<<"\n";

    }
    cout<<sum;
}

int main()
{

    int n,k;
    cin>>n>>k;
    string str;
    cin>>str;
    sort(str.begin(),str.end());
   // cout<<str;
    funct(str,k,n);

}

/*"Success isn't permanent, failure isn't fatal,
    it's the courage to continue that counts"

⠀     ⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄
⠀     ⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧
⠀     ⠀⠀⠀⠀⠀⠀⣸⣿⠁  HIMANSHU⠀⠈⣿⣇
⠀     ⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿
⠀     ⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟
⠀     ⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀
⠀     ⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀
⠀     ⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄
⠀     ⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿
⠀     ⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸
⠀     ⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈
⠀     ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀
⠀     ⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂
⠀     ⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁
*/
#include<bits/stdc++.h>
using namespace std;
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define pfis(a) printf("%d ",a);
#define pfls(a) printf("%lld ",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(int i=a;i<b;i++)
#define pb(a) push_back(a);
#define mp(a,b) make_pair(a,b)
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define sorrev(v) sort(v.begin(),v.end(),greater<ll>())
#define uni(v) unique(v.begin(),v.end())
#define bs binary_search
#define lb(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()
#define ub(v,x) upper_bound(v.begin(),v.end(),x)-v.begin()
#define ll long long
#define F first
#define S second
#define vi vector<ll>
#define vc vector<char>
#define endl "\n"
#define deci fixed<<setprecision(9)
const ll mod = 1e9 + 7;
#define N 1000005
int main()
{
ll n,k;
sfl(n);
sfl(k);
ll arr[n+1];
string str;
cin>>str;
f(i,0,str.length())
{
    arr[i]=str[i]-'a'+1;
   // cout<<arr[i]<<endl;
}
sort(arr,arr+n);
ll wt=arr[0],cnt=0,f1=0,v1=arr[0],brr[27];
memset(brr,0,sizeof(brr));
f(i,1,n)
{
         if(cnt==k-1)
        {
            f1=1;
            break;
        }
    if(arr[i]-v1>1&&brr[arr[i]]==0)
    {
         //  cout<<arr[i]-v1<<endl;
         brr[arr[i]]=1;
        cnt++;
        wt+=arr[i];
        v1=arr[i];
         if(cnt==k-1)
        {
            f1=1;
            break;
        }
    }
}
if(f1||k==1)
{
    cout<<wt<<endl;
}
else
{
    cout<<-1<<endl;
}

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,i,j,sum=0,f=0;
    string s;
    cin>>n>>k;
    cin>>s;
    sort(s.begin(),s.end());
    char c=s[0];sum=s[0]-96;
    if(k==1){
        cout<<sum<<endl;
        return 0;
    }
    for(i=1;i<n;i++){
        if(s[i]>=c+2){
            c=s[i];
            sum=sum+(s[i]-96);
            k--;
        }
        if(k<=1){
            f=1;
            break;
        }
    }
    if(f)
        cout<<sum<<endl;
    else
        cout<<-1<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    while(cin>>n>>k){
        char lett[n];
        cin>> lett;
        int letn[n];
        for(int i=0;i<n;i++)
        {
            letn[i] = lett[i] - 96;
            //cout << "lett[i]: "<< lett[i] << " letn[i]" << letn[i] <<endl;
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n-i-1;j++)
            {
                int temp;
                if(letn[j]>letn[j+1])
                {
                    temp = letn[j];
                    letn[j] = letn[j+1];
                    letn[j+1] = temp;
                }
            }
        }
        int weight,minimal=100000,prev,ksucker;
        bool chk = false;
        bool jhakanaka;
        for(int i=0;i<n-k+1;i++)
        {
            ksucker = k-1;
            weight = letn[i];
            prev = letn[i];
            //cout << "\n\n:"<<letn[i]<< " i: " <<i<<endl;
            jhakanaka = false;
            for(int j=i+1;j<n;j++)
            {
                if(prev>letn[j]+1 || prev+1<letn[j]){

                    prev = letn[j];
                    weight+=letn[j];
                    ksucker--;
                    //cout << "J: "<< j <<endl;
                    //cout << "prev:" <<prev << " letn[j] :" << letn[j] <<" weight: "<<weight<<" ksucker:" <<ksucker <<endl;
                     if(ksucker==0){
                        chk = true;
                        jhakanaka = true;
                        //cout <<"vitre:" <<chk <<endl;
                        break;
                    }

                }
            }
            //cout << chk <<endl;
            //cout << "weight: "<< weight << " minimal: "<< minimal <<endl;
            if((weight<minimal)&&jhakanaka) minimal = weight;
            if(!chk) minimal = -1;
            if(k==1 && n>k) minimal = letn[0];
            if(n==1&&k==1) minimal = letn[0];
        }
        cout << minimal <<endl;
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
#define F first
#define S second
ll n , k , a[100] , ans , x ;
string s ;
int main ()
{
	cin >> n >> k >> s ;
	for ( ll i = 1 ; i <= n ; i ++ )
		a[i] = s[i-1] - 'a' + 1 ;
	sort ( a + 1 , a + n + 1 ) ;
	ans = x = a[1] ;
	k -- ;
	for ( ll i = 2 ; i <= n ; i ++ ){
		if ( a[i] >= x + 2 and k ) {
			x = a[i] ;
			ans += x ;
			k -- ;
		}
	}
	if ( k ) return cout << - 1, 0 ;
	cout << ans ;
}

#include <iostream>
#include <cstring>
using std::cin;
using std::cout;
using std::endl;

void swap(char& a, char& b){
    char temp = a;
    a = b;
    b = temp;
}

int partition(char arr[], int low, int high){
    char pivot = arr[(low + high)/2];
    int i = low -1, j = high + 1;

    while (true){
        do{
            i++;
        }while(arr[i] < pivot);

        do{
            j--;
        }while(arr[j] > pivot);

        if (i >= j) return j;
        swap(arr[i], arr[j]);
    }
}

void QuickSort(char arr[], int low, int high){
    if (low < high){
        int pi = partition(arr, low, high);
        QuickSort(arr, low, pi);
        QuickSort(arr, pi + 1, high);
    }
}

void bubble(char arr[], int size){
    for (int i = 0; i < size - 1; ++i){
        for (int j = i + 1; j < size; ++j){
            if (arr[i] > arr[j]){
                swap(arr[i],arr[j]);
            }
        }
    }
}

void move(char arr[], int index, int size){
    for (int i = index; i < size - 1; ++i)
        arr[i] = arr[i + 1];
    arr[size - 1] = 0;
}

void rocket(char stages[], int amount, int len){
    QuickSort(stages, 0, amount - 1);
    //cout << stages << endl;
    if (len > 13){
        cout << -1;
        return;
    }
    int sum = 0, index = 0;
    while (index != len - 1){
        if (stages[index + 1] - stages[index] > 1){
            sum += (stages[index] - 96);
            index++;
        }
        else{
            if (stages[index + 1] == stages[amount - 1]) {
                cout << -1;
                return;
            }
            while (stages[index + 1] - stages[index] <= 1){
                move(stages, index + 1, amount);
            }
        }
    }
    sum += (stages[len - 1] - 96);
    cout << sum;
}

int main(){
    int n, k;
    cin >> n >> k;
    char stages[n + 1];
    cin >> stages;
    rocket(stages, n, k);
}

#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define fi first
#define se second
#define mp make_pair
#define v vector<int>
#define vl vector<long long>
#define vb vector<bool>
#define vv vector<vector<pair<int,int> > >
#define ii pair<int,int>
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define ll long long
#define EPS 1e-9
#define pb push_back()
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(0);
	int n,k;
	cin>>n>>k;
	string ph;
	cin>>ph;
	sort(ph.begin(),ph.end());
	k--;
	int idx=0;
	bool found=0;
	ll ans=ph[0]-'a'+1;
	if(k==0){
		//adebug(1);
		cout<<ans;
		return 0;
	}
	for (int i = 1; i < ph.size(); ++i)
	{
		debug(idx);

		debug(ph[i]-ph[idx]);
		debugs(ph[i],ph[idx]);
		if(ph[i]-ph[idx]<=1||ph[i]==ph[idx]){
			//idx++;
			continue;
		}
		else{
			k--;
			idx=i;
			debugs(ph[i],ph[i]-'a'+1);
			ans+=ph[i]-'a'+1;
		}
		if(!k){
			found=1;
			break;
		}
	}
	if(!found){
		cout<<-1;
		return 0;
	}
	cout<<ans;
	return 0;
}

#include <iostream>
#include <string>
using namespace std;
int n, k;
string s;
int alphabet[27];
int main() {
	cin >> n >> k;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		alphabet[(s[i] - 97)]++;
	}
	int curv = 0;
	int sum = 0;
	while (curv < 26 && k > 0) {
		if (alphabet[curv]) {
			sum += (curv + 1);
			curv += 2;
			k--;
		}
		else {
			curv++;
		}
	}
	if (k != 0) {
		cout << -1 << endl;
	}
	else cout << sum << endl;
}

#include <iostream>
#include <algorithm>
#include <string>

using namespace std;
char a[52],s[52];
int main() {
  int n,k;
  cin >> n >> k;
  cin >> s;
  sort(s,s+n);
  long long cnt=1,ans=s[0]-'a'+1;
  a[0]=s[0];
  //cout << ans <<endl;

  for(int i=1;i<n;i++) {
        if(cnt==k)break;
       if(s[i]-a[cnt-1]>=2){
            a[cnt]=s[i];
          ans+=(a[cnt]-'a'+1);
        cnt++;
       }
  }
 // cout << cnt <<endl;
  if(cnt==k) cout << ans <<endl;
  else cout << "-1" <<endl;
}

#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int a[55];
int main()
{
	int n, k;
	cin >> n >> k;
	string ch;
	cin >> ch;
	if (k == 0) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		a[i] = ch[i] - 'a' + 1;
	}
	sort(a, a + n);
	int sum = a[0],s=1,t=a[0];
	for (int i = 1; i < n; i++) {
		if (s == k)
			break;
		if (a[i] > t + 1) {
			sum += a[i];
			t = a[i];
			s++;
		}
		else
			continue;
	}
	if (s < k)
		cout << -1 << endl;
	else
		cout << sum << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    int l=s.length();
    for (int i = 0; i < l-1; i++) {
      for (int j = i+1; j < l; j++) {
         if (s[i] > s[j]) {
            char temp = s[i];
            s[i] = s[j];
            s[j] = temp;
         }
      }
   }
   //cout<<s[0]<<endl;
    int sum=s[0]-96;
    //sum+=s[0]-96;
    char c=s[0];
    //cout<<sum<<endl;
    int h=1;
    int x=m;
    for (int i = 1; i <l;i++) {

           // cout<<s[i]<<endl;
        if(s[i]-c>=2&&h<m)
        {

            sum+=(s[i]-96);
			h++;
            c=s[i];
            //cout<<h<<endl;

        }
        if(h==m)break;

    }

//    printf("%d %d\n",cnt,sum);
    if(h!=m)
    cout<<"-1"<<endl;
    else
    cout<<sum<<endl;
    return 0;
}

#include<iostream>
    #include<algorithm>
    using namespace std;

    char a[1000];
    char b[1000];
    int cmp(char a,char b)
    {
    	return a-'a'<b-'a';
    }
    int main()
    {
    	int m,n,i;
    	while(cin>>m)
    	{
    		cin>>n;
    		for(i=0;i<m;i++)
    		{
    			cin>>a[i];
    		}
    		sort(a,a+m,cmp);
    	int sum=a[0]-'a'+1;
    	int k=1;
    	int rec=0;
    	     for(i=1;i<m;i++)
    	     {
    	     	if(k>=n) break;
    	     	rec+=a[i]-a[i-1];
    	     	if(rec>1)
    	     	{
    	     		sum+=a[i]-'a'+1;
    	     		rec=0;
    	     		k++;
    			}
    		 }
    		 if(k<n) cout<<"-1"<<endl;
    		 else cout<<sum<<endl;

    	}
    }

#include<stdio.h>
int main()
{bool rec[26]={0};
int n,k;
char c;
scanf("%d%d",&n,&k);
for(int i=0;i<=n;i++)
	{scanf("%c",&c);
rec[c-'a']=1;}
int now=0,ans=0;
while(k>0)
{if(rec[now]==1)
{k--;ans+=(now+1);now+=2;}
else
	now++;
if(now>25)
	break;}
if(k>0)
	printf("-1");
else
	printf("%d",ans);}

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	int n, k, ans = 0, cnt = 1, i;
	char prev;
	string s;
	cin >> n >> k >> s;
	sort(s.begin(), s.end());
	ans = s[0] - 96;
	prev = s[0];
	for (i = 1; i < n; i++) {
		if (cnt == k) {
			break;
		}
		if (s[i] - prev > 1) {
			ans += s[i] - 96;
			prev = s[i];
			cnt++;
		}
	}
	if (cnt < k) {
		cout << -1;
	} else {
		cout << ans;
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,k;
    string s;
    char last='a'-2;
    int ans=0,len=0;
    cin>>n>>k>>s;
    sort(s.begin(),s.end());
    for (int i=0;i<=s.size()-1;i++)
        if (s[i]>=last+2)
        {
            last=s[i];
            ans+=s[i]-96;
            len++;
            if (len>=k)
            {
            	cout<<ans<<endl;
            	return 0;
			}
        }
    cout<<-1<<endl;
    return 0;
}

#include<bits/stdc++.h>
#include<string>
using namespace std;
void sortString(string &str)
{
   sort(str.begin(), str.end());
   //cout << str;
}
int main()
{
    int n,k;
    cin>>n>>k;
    string str;
cin>>str;
    char ans[k+10];
    int r;
   sortString(str);
  // cout<<str<<endl;
     //for(int i=0;i<n;i++)
       // cout<<str[i];
    ans[0]=str[0];
    int j=1,i;
    //cout<<str[0]<<" "<<str[1]<<endl;
    for(i=1;i<n&&j<k;i++)
    {//cout<<"i is"<<i<<"val"<<str[i]<<endl;
        r=str[i]-ans[j-1];
        //cout<<"r is"<<r;
        if(r>1){
        //cout<<str[i]<<str[i]-97<<endl;

            //cout<<(str[i]-str[i-1])<<"hey"<<endl;
            ans[j]=str[i];
            j++;
        }

 if(j==k)
 {

 break;}
    }
    //cout<<"heloo"<<endl;
//cout<<j<<" "<<k<<" hi"<<endl;;
    if(j!=k)
        cout<<"-1"<<endl;
    else{int sum=0;
    for(int j=0;j<k;j++)
        {
        sum=sum+ans[j]-96;

        }

        cout<<sum<<endl;
        }

}

#include<bits/stdc++.h>
using namespace std;
int n,k;string str;
int main()
{
	cin>>n>>k>>str,--k;
	sort(str.begin(),str.end());
	int ans=str[0]-'a'+1;
	if(!k)return 0*printf("%d\n",ans);
	char last=str[0];
	for(int i=1;i<n;++i)
		if(str[i]-last>1){
			ans+=str[i]-'a'+1,last=str[i];
			if(!--k)return 0*printf("%d\n",ans);
		}
	return 0*puts("-1");
}

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{

   int n , k , i , x  = 0, y =0 , w = 0 , j  =  0 ;

   cin>>n>>k;

   if(n<k)
   {
       cout<<"-1";
       return 0 ;
   }
   char a[n+1] ;
   cin>>a;
   sort(a,a+n);
   y = 1 ;
   w = (a[0] - 96 );
   if(y==k)
        {
            cout<<w;
            return 0 ;
        }

   for(i=1;i<n;i++)
   {

        if(a[i] >= (a[j] + 2) )
        {
            w+= a[i] - 96  ;
            y++;
            j = i ;
        }
        if(y==k)
        {
            cout<<w;
            return 0 ;
        }

   }
   cout<<"-1";

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s1;
    int n,k;
    cin>>n>>k;
    int a[n]={},sum=0,l=0;
    cin>>s1;
    sort(s1.begin(),s1.end());
    for(int i=0;i<s1.length();i++)
    {
        a[i]=s1[i]-96;
    }
    if(k==1)
    {
    cout<<a[0];
    return 0;
    }
   int p=a[0];
   sum=p;
    for(int i=0;i<n-1;i++)
    {
        if((a[i+1]-p)>=2)
        {
            p=a[i+1];
            sum+=p;
            l++;
            //cout<<l<<" l"<<endl;
            //cout<<sum<<endl;
            if(l==(k-1))
            {
                cout<<sum;
                return 0;
            }
        }
    }
    cout<<-1;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;

// read the question correctly (is y a vowel?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)

const int mx = 123456;
const double pi = acos(-1);
int ar[mx],x[mx],y[mx];
map<char,int>mp1;
set<char>se;

int main(){

    // freopen("in.txt","r", stdin);
    // freopen("out.txt","w", stdout);
    char ch = 'a';
    for(int i = 1; i <= 26; i++){
        mp1[ch] = i;
        ch++;
    }
    int n,k,res;
    while(scanf("%d%d",&n,&k)==2){
         string st;
         cin>>st;
         int sz = st.size();
         for(int j = 0; j < sz; j++){
            se.insert(st[j]);
         }
        sort(st.begin(), st.end());
       // cout<<st<<endl;
        set<char>::iterator it;
        int ans = 12345678;
        res = 0;
        int cnt = 0;
        int p = se.size();
        if((int)se.size() % 2 == 1) p++;
        p = p/2;
        char chh;
        int j = 0;
        for(it=se.begin(); it!=se.end(); it++){

                if(j == 0){
                   chh = *it;
                    res = res + mp1[*it];
                    cnt++;
                    j++;
                    if(cnt == k)break;
                    continue;
                }
                if(mp1[*it] == mp1[chh] + 1){

                    continue;
                }
                else {
                    res += mp1[*it];
                    chh = *it;
                    cnt ++;
                    if(cnt == k)break;
                }

        }
        se.clear();
        if(cnt!=k) printf("-1\n");
        else printf("%d\n",res);

    }

return 0;

}

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

char s[50];

int main(){
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++){
		cin >> s[i];
	}
	sort(s, s + n);
	int sum = 0;
	sum += s[0] - 'a' + 1;
	int last = s[0];
	int counter = 1;
	if (counter == k){
		cout << sum;
		exit(0);
	}
	for (int i = 1; i < n; i++){
		if (s[i] - last >= 2){
			sum += s[i] - 'a' + 1;
			last = s[i];
			counter++;
			if (counter == k){
				cout << sum;
				exit(0);
			}
		}
	}
	cout << -1;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	int i,j;
	char a[n];
	for(i=0;i<n;i++) a[i]=s[i];
	sort(a,a+n);
	long int sum=0;
	sum=a[0]-96;
	j=1;
	int c=0;
	string s1;
	s1.push_back(a[0]);
	//for(i=0;i<=n;i++) cout<<a[i]<<" ";
	//cout<<endl;
	for(i=1;i<n;i++)
	{
		if(j==k)
		{
			c=1;
			break;
		}
		if(abs(a[i]-s1[j-1])>=2)
		{
			s1.push_back(a[i]);
			j++;
			sum=sum+a[i]-96;
			//cout<<a[i]<<" ";
		}
	}
	if(c==1||j==k)
		cout<<sum<<endl;
	else
		cout<<"-1"<<endl;
return 0;
}

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int n,k;
	cin>>n;
	cin>>k;
	string s;
	cin>>s;
	sort(s.begin(),s.end());
	int w=0,i,count=1;
	char ch,ch2;
	ch=s.at(0);
	w=ch-'a'+1;
	for(i=1;i<s.length();i++){
		if(count==k)
			break;
		ch2=s.at(i);
		if(ch2-ch>1){
			w+=ch2-'a'+1;
			count++;
			ch=ch2;
		}

	}
	if(count<k)
		cout<<"-1\n";
	else
		cout<<w<<endl;
}

#include<bits/stdc++.h>
using namespace std;
int n,k,ans,sum;
char str[51],l;
int num[51];

int main()
{
    cin>>n>>k;
    cin>>str;
    sort(str,str+n);
    for(int i=0;i<n;i++)
    {
        if(i==0)
        {
            ans++;
            sum+=str[i]-'a'+1;
            l=str[i];
        }
        else if(str[i]>l+1)
        {
            ans++;
            sum+=str[i]-'a'+1;
            l=str[i];
        }
        if(ans==k)break;
    }
    if(ans!=k)cout<<-1<<endl;
    else cout<<sum<<endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    char last='a'-2;
    int ans=0;
    int len=0;
    for(int i=0;i<n;i++)
        if(s[i]>=last+2)
        {
            last=s[i];
            ans+=s[i]-'a'+1;
            len++;
            if(len>=k)
                cout<<ans,exit(0);
        }
    cout<<-1;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, k, ans;
    string s;
    cin>>n>>k>>s;
    sort(s.begin(), s.end());
    ans=s[0]-96;
    k--;
    if (k == 0)
        cout<<ans;
    else
    {
        char pre=s[0];
        for (int i = 1; i<n; i++){
            if (s[i]-pre>1){
                ans += s[i]-96;
                pre = s[i];
                k--;
                if (k==0){
                    cout<<ans;
                    return 0;
                }
            }
        }
        cout <<"-1"<<endl;
    }

    return 0;
}

#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
	int n, k;
	char a[55];
	int f[55];
	cin >> n >> k;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
		f[i] = int(a[i]) - 2 * 48;
	}
	for (int i = 1; i <= n; i++){
		int s = 10000000000, q, z = 0;
		for (int j = i; j <= n; j++){
			if (s > f[j]){
				s = f[j];
				z = j;
			}
		}
		q = f[i];
		f[i] = s;
		f[z] = q;
	}
	int x = 0, y = 0, ans = 0;
	f[0] = -1;
	for (int i = 1; i <= n; i++){
		if (f[i] - 2 >= f[y]){
			x++;
			y = i;
			ans += f[i];
		}
		if (x == k){
			cout << ans;
			return(0);
		}
	}
	cout << -1;
	return 0;
}

    #include<bits/stdc++.h>
using namespace std;
int main() {
   int  a[30] = {};
    int n, m;
    char c;
    cin >> n >> m;
    for(int i = 0 ; i < n ; i ++){
		cin >> c;
		a[c - 'a' + 1] = 1;
    }
    int k = 0, res = 0, f= 0;
    for(int i = 1 ; i <= 26 ;i ++){
		if(a[i])res += i,a[i + 1] = 0, k ++;
		if(k == m){f = 1;break;}
    }
    if(f)cout << res;
    else cout << -1;
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e6;

char str[100];

int main()
{
    int n, m;
    while(~scanf("%d %d", &n, &m))
    {
        scanf("%s", str);
        int len = strlen(str);
        sort(str, str+len);
        int mins = 1e9;
        for(int k = 0; k<len; k++)
        {
            int ans = str[k] - 'a' + 1, t = m-1;
            char ch = str[k];
            for(int i=k+1; i<len; i++)
            {
                if(t == 0)
                    break;
                if(str[i]>ch+1)
                {
                    ch = str[i];
                    ans += ch - 'a' + 1;
                    t--;
                    //cout<<t<<endl;
                }

            }
            if(t == 0)
            {
                //cout<<ans<<endl;
                mins = min(mins, ans);
            }

        }
        if(mins == 1e9)
        {
            cout<<-1<<endl;
        }
        else
            cout<<mins<<endl;

    }
    return 0;
}
/*************
50 13
qwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa
************/

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

int n, k;
char s[100];
int vis[100];
int ans = 0;

int main(){
	scanf("%d %d", &n, &k);
	scanf("%s", s);
	int len = strlen(s);
	sort(s, s+len);
	for(int i = 0; i < len; i++){
		if(!vis[i] && k > 0){
			ans += s[i]-'a'+1;
			k--;
			for(int j = i+1; j < len; j++){
				if(s[j] == s[i])
					vis[j] = 1;
				if(s[j] == s[i]+1)
					vis[j] = 1;
			}
		}
	}
	if(k > 0){
		printf("-1\n");
	}
	else
		printf("%d\n", ans);
return 0;
}

#include <iostream>
#include<vector>
#include<string>
#include <algorithm>
using namespace std;

int main() {

char a[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
	int n,k;
	cin>>n>>k;
	char *b=new char [n];
	for(int i=0;i<n;i++){
		cin>>b[i];
	}
	sort(b,(b+n));
	char temp=b[0];
	int count=0;
	int sum=0;

	sum=(b[0]-'a')+1;
	count=1;
	int count2=1;
	int flag=1;
	int flag2=0;
for(int i=1;count<n&&count2<k;i++){
	//	cout<<b[count]<<endl;
		if(b[count]>temp&&temp+1!=b[count]-0&&temp!=b[count]){
				sum+=(b[count]-'a')+1;
				temp=b[count];
			count2++;
			flag++;

		}else{

		}

			count++;
	}
	if(flag==k){

		cout<<sum;

	}else{

		cout<<-1;
	}

    return 0;

}

/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "

using namespace std;
///check n=1;
///check corner case;

int main()
{
    ll n,i,j,k=0,cc=0;
    cin>>n>>k;
    string str;
    cin>>str;
    sort(str.begin(),str.end());
    if(n==1 || k==1){
        cout<<str[0]-96<<endl;
        return 0;
    }
    for(i=0;i<n;i++){
        cc+=str[i]-96;
        char ch=str[i]+2;
        k--;
        for(j=i+1;j<n;j++){
            //
            if(ch<=str[j]){
                //cout<<ch<<spc<<str[j]<<endl;
                cc+=str[j]-96;
                ch=str[j]+2;
                k--;
            }
            //cout<<k<<endl;
            if(k<=0){
                cout<<cc<<endl;
                return 0;
            }

        }
break;
    }
    cout<<-1<<endl;
return 0;
return 0;
}

// 贪心题，首先将字符串按从小到大排序，然后从前往后取字符，只要不是连续的字符就可以取
#include <iostream>
#include <string>
#include <algorithm>

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

    int n, k;
    std::cin >> n >> k;

    std::string Str;
    std::cin >> Str;

    std::sort(Str.begin(), Str.end());

    int Ans = Str[0] - 'a' + 1; // 头字符肯定可以取，先取一个看看
    --k;

    if (k == 0)
    {
        std::cout << Ans << std::endl;
    }
    else
    {
        auto Pre = Str[0];  // 记录上一次取得的字符
        for (int i = 1; i < n; ++i)
        {
            if (Str[i] - Pre > 1)   // 不连续则可以取
            {
                Ans += Str[i] - 'a' + 1;
                Pre = Str[i];

                if (--k == 0)
                {
                    std::cout << Ans << std::endl;

                    return 0;
                }
            }
        }

        std::cout << -1 << std::endl;
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int n,k,ans=2147400000,a[55];
char ch[55];
int main()
{
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++) cin >> ch[i],a[i]=ch[i]-96;;
	sort(a+1,a+n+1);
	for(int i=1;i<=n-k+1;i++)
	{
		char lat=-2;
		int sum=0,su=0,fi=a[i];
		for(int j=i;j<=n;j++)
		{
			if(a[j]-lat>=2)
			{
				sum+=a[j];
				lat=a[j];
				su++;
			}
			if(su==k)
			{
				ans=min(ans,sum);
				break;
			}
		}
	}
	if(ans==2147400000) printf("-1");
	else printf("%d",ans);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int>s;
    for (int i = 0; i < n; i++)
    {
        char c;
        cin >> c;
        if (c == 'a')
        {
            s.push_back(1);
        }
        if (c == 'b')
        {
            s.push_back(2);
        }
        if (c == 'c')
        {
            s.push_back(3);
        }
        if (c == 'd')
        {
            s.push_back(4);
        }
        if (c == 'e')
        {
            s.push_back(5);
        }
        if (c == 'f')
        {
            s.push_back(6);
        }
        if (c == 'g')
        {
            s.push_back(7);
        }
        if (c == 'h')
        {
            s.push_back(8);
        }
        if (c == 'i')
        {
            s.push_back(9);
        }
        if (c == 'j')
        {
            s.push_back(10);
        }
        if (c == 'k')
        {
            s.push_back(11);
        }
        if (c == 'l')
        {
            s.push_back(12);
        }
        if (c == 'm')
        {
            s.push_back(13);
        }
        if (c == 'n')
        {
            s.push_back(14);
        }

        if (c == 'o')
        {
            s.push_back(15);
        }
        if (c == 'p')
        {
            s.push_back(16);
        }
        if (c == 'q')
        {
            s.push_back(17);
        }
        if (c == 'r')
        {
            s.push_back(18);
        }
        if (c == 's')
        {
            s.push_back(19);
        }
        if (c == 't')
        {
            s.push_back(20);
        }
        if (c == 'u')
        {
            s.push_back(21);
        }
        if (c == 'v')
        {
            s.push_back(22);
        }
        if (c == 'w')
        {
            s.push_back(23);
        }
        if (c == 'x')
        {
            s.push_back(24);
        }
        if (c == 'y')
        {
            s.push_back(25);
        }
        if (c == 'z')
        {
            s.push_back(26);
        }
    }
    sort(s.begin(), s.end());
    int sum = s[0];
    int z = 1;
    for (int i = 1; i < s.size(); i++)
    {
        if (z == m)
        {
            cout << sum << endl;
            return 0;
        }
        if (s[i] - s[i - 1] > 1)
        {
            sum += s[i];
            z++;
        }
        else
        {
            s[i]= s[i-1];
        }
    }
    if (z < m)
    {
        cout << -1 << endl;
        return 0;
    }
    cout << sum << endl;
}

#include<iostream>
#include<algorithm>
using namespace std;
const int MAX  = 500;
int main()
{
	int n, k, a[130], ans = MAX;
	memset(a, 0, 130 * sizeof(int));
	char c;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> c;
		a[c]++;
	}
	for (int i = 'a'; i <= 'z'; i++)
	{
		if (a[i] > 0)
		{
			int j = i, jsave = j-2 , kcp = k, sum = 0;
			while (kcp > 0 && j<='z')
			{
				if (j - jsave >= 2 && a[j]>0)
				{
					sum += j - 'a' + 1;
					jsave = j;
					kcp--;
				}
				j++;
			}
			if(kcp==0)
				ans = min(sum, ans);
		}
	}
	if (ans == MAX)
		cout << -1;
	else cout << ans;
	//system("pause");
}

#include<bits/stdc++.h>
using namespace std;
int a[10005];
int main()
{
    string s;
    int n,m;
    cin >> n>>m>>s;
    int p = 0;
    if(s.size() <m) {printf("-1\n");return 0;}
    for(int i = 0; i < s.size(); i++){
        a[p++] =(int)(s[i] - 'a' + 1);
    }

    sort(a, a+p);
   /* for(int i = 0; i < p; i++){
        printf("%d ",a[i]);
    }*/
    int sum = 0;
    sum += a[0];
    int flag = 1;
    int x = 0;
    for(int i = 1 ; i < p; i++){
        if(flag == m) break;
        if(a[i] > a[x] + 1){
            sum += a[i];
            flag++;
            x = i;
        }
        else continue;

    }
    if(flag < m) printf("-1\n");
    else printf("%d\n",sum);
}

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int map[256];
int main()
{
	int len, n;
	string s;
	cin >> len >> n >> s;
	for (int i = 0; i < s.length(); i++)
	{
		map[s[i]] = 1;
	}
	int last = 0;
	int weight = 0;
	for (int i = 0; i < 256 && n; i++)
	{
		if (map[i] == 1 && i - last >= 2)
		{
			weight += i - 'a' + 1;
			last = i;
			n--;
		}
	}
	if (n == 0)
		cout << weight << endl;
	else
		cout << -1 << endl;
    return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
#include <map>

using namespace std;

bool compare(char c1, char c2){
	if(c1 > c2)
		return false;
	return true;
}

int main(){
	int n;
	cin >> n;
	int k;
	cin >> k;
	int* a = new int[26];
	char ch;
	for(int i = 0; i < 26; i++)
		a[i] = 0;
	for(int i = 0; i < n; i++){
		cin >> ch;
		a[ch - 'a']++;
	}

	if(n == 0 || k > n){
		cout << -1;
		return 0;
	}
	int c = - 3;
	int ans = 0;
	int j = 0;
	int it = 0;
	while(it < k) {
		while(j - c < 2 || a[j] <= 0){
			if(j > 25)
				break;
			j++;
		}
		if(j > 25)
			break;
		ans += j + 1;
		c = j;
		it++;
	}
	if(it == k)
		cout << ans;
	else
		cout << -1;

	//system("pause");
	return 0;
}

#include<iostream>
using namespace std;
int main(){
    int n,k; cin>>n>>k;
    string s; cin>>s;
    for(int i=1;i<n;i++){
        for(int j=i-1;j>=0;j--){
            if(s[j]>s[j+1]){
                int dum;
                dum=s[j+1];
                s[j+1]=s[j];
                s[j]=dum;
                }
            else break;
            }}
 int r=1,c=1,d=s[0]-96,i=0;
 while(r<n&&c<k){
            if((s[r]-s[i])>1){d=d+s[r]-96;i=r;c++;}
            r++;
        }
if(c<k){cout<<-1;}
else{cout<<d;}
    }

#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int a[55];
int main()
{
	int n, k;
	cin >> n >> k;
	string ch;
	cin >> ch;
	if (k == 0) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		a[i] = ch[i] - 'a' + 1;
	}
	sort(a, a + n);
	int sum = a[0],s=1,t=a[0];
	for (int i = 1; i < n; i++) {
		if (s == k)
			break;
		if (a[i] > t + 1) {
			sum += a[i];
			t = a[i];
			s++;
		}
		else
			continue;
	}
	if (s < k)
		cout << -1 << endl;
	else
		cout << sum << endl;
	return 0;
}

#include<iostream>
#include<stdio.h>
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<string>
using namespace std;

typedef long long int int64;
#define ret return 0;

int lastR[100000], lastL[100000];
int main() {
#pragma warning(disable:4996);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // _DEBUG
	int n, k, ans =0;
	cin >> n >> k;
	int massiv[26] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
	string a;
	cin >> a;
	for (int i = 0; i < a.length(); i++) {
		massiv[a[i] - 'a'] = 1;
	}
	for (int i = 0; i < 26&& k >0; i++) {
		if (massiv[i]) {
			ans += i + 1;
			k--;
			i++;
		}
	}
	if (k > 0) cout << -1;
	else cout << ans;
	return 0;
}

#include <iostream>
#include <algorithm>
#include <string>

using namespace std;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,k;
  cin>>n>>k;
  if (k>13) cout<<-1;
  else{
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    int p=-1, w=0;
    for (int i=0; i<n; i++){
      int c=s[i]-96;
      if ((c-p)>1) {p=c; w+=c; k--;}
      if (k==0) break;
    }
    if (k==0) cout<<w<<"\n";
    else cout<<-1<<"\n";
    return 0;
  }
}

#include<iostream>
using namespace std;
int a[30];
int main() {
	int n; int k;
	while (cin >> n >> k) {
///		for (int i = 1; i <= 30; i++)a[i] = 0;
		char s;
		for (int i = 1; i <= n; i++) {
			cin >> s;
			a[s - '0'-48]++;
			//cout << s - '0' - 48 << endl;
		}
		int sum = 0; int ans = 0; int i;
		for ( i = 1; i <= 26; i++) {
			if (a[i] >= 1) {
				ans++;  sum += i; i++;
			//	cout <<"i  is "<< i << endl;
				if (ans == k) {
					cout << sum << endl;
					return 0;//break;
				}
			}

		}if (i >= 26)cout << "-1" << endl;

	}

	return 0;
}

#include<bits/stdc++.h>

#define pb push_back
#define ffor(l,r) for(int i=l;i<r;i++)
#define dfor(l,r) for(int i=l;i>=r;i--)
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define ll long long
#define modulo 1e9+7
#define fi first
#define se second
#define umap unordered_map
#define uset unordered_set
#define printA(arr,e) ffor(0,e) cout<<arr[i]<<" "
#define printC(container) for(auto it : container) cout<<it<<" "
#define desc(type) greater<type>()

using namespace std;

bool test = 0;
void solve() {
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    char pre;
    int ans  = s[0]- 96;
    pre = s[0] ;
    // for(int i=0;i<n;i++) cout<<s[i]<<" ";
    int j = 1;
    bool flag = false;
    for(int i=1;i<n;i++){

        if(pre == s[i]-1 || pre == s[i]) continue;

        // cout<<pre<<" ";
        pre = s[i];
        if(j==m){
            flag = true;
            break;
        }
        ans += (int)(s[i] - 96);
        j++;

    }
    if(j==m){
        flag = true;
    }
    if(flag)
        cout<<ans;
    else
        cout<<"-1";
}

int main() {
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    if (test) {
        int t;
        cin>>t;
        while (t--)
            solve();
    }
    else
        solve();

    return 0;
}

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	int i,j=1,x=0,y,count=0,n,k;
	string s;
	cin>>n>>k;
	cin>>s;
	sort(s.begin(),s.end());
	y=s[0];
	x=s[0]-'a'+1;
	for(i=1;i<n&&j<k;i++)
	{
		if(j<=k)
		if(s[i]-y>1)
		{
			y=s[i];
			x=x+s[i]-'a'+1;
			j++;
		}
		if(j==k)
			break;
	}
	if(j==k)
	cout<<x;
	else
	cout<<-1;
	return 0;
}

 #include<bits/stdc++.h>
using namespace std;
string s;
// map<char,int> m;
int a[100];
int main(){
	int n,k;
	cin>>n>>k;
	cin>>s;
	// for(int i=0;i<s.size();i++){
	// 	m[s[i]]=1;
	// }
	sort(s.begin(),s.end());
	int sum=s[0]-'a'+1;
	int c=1;
	char temp=s[0];
	for(int i=1;i<s.size();i++){
		if(c==k)
				break;
		if(s[i]-temp>=2) {
			sum+=s[i]-'a'+1;
			temp=s[i];
			c++;
		}
	}
	if(c>=k) cout<<sum<<endl;
	else cout<<-1<<endl;
	return 0;
}

#include<bits/stdc++.h>

using namespace std;
int main(){
    int x, y;
    scanf("%d %d", &x, &y);
    string a;
    cin>>a;
    sort(a.begin(), a.end());
    int sz = a.size() - y;
    int s = a.size(), mn = 100000000;

    for(int i = 0; i <= sz; i++){
        int an = a[i] - 96;
        int last = a[i] - 96, c = 1;
        for(int j = i + 1; j < s; j++){
            if(c == y) break;
            int lol = a[j] - 96;
            if((last+1) != lol && last != lol){
                last = lol;
                an += lol;
                c++;
            }
        }

        if(c == y) mn = min(mn, an);
    }

    if(mn != 100000000) printf("%d\n", mn);
    else printf("-1\n");

    return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main(){

    //freopen("aain.txt", "r", stdin);

    int n, k;

    cin>>n>>k;

    string s;

    int i;

    cin>>s;

    if(n == 1){
        cout<<s[0] - 'a' + 1;
        return 0;
    }

    sort(s.begin(), s.end());

    if(k == 1){
        cout<<s[0] - 'a' + 1;
        return 0;
    }

    int weight = s[0] - 'a' + 1;

    char current = s[0];
    k--;

    for(i = 1; i < n; i++){

            if(s[i] - current > 1){
                weight = weight + s[i] - 'a' + 1;
                current = s[i];
                k--;
            }

        if(k == 0){
            cout<<weight;
            return 0;
        }

    }
        cout<<"-1";

    return 0;

}

#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define pi 3.14159265358979
using namespace std;
typedef long long ll;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s;
int n,k;
cin>>n>>k;
cin>>s;
sort(s.begin(),s.end());
vector<char>v;
v.pb(s[0]);
int cost=0;
for(int i=1;i<int(s.size());i++)
{
	if(int(s[i])-int(v[int(v.size())-1])>=2)
	{
		v.pb(s[i]);
	}

}
if(int(v.size())>=k)
{
for(int i=0;i<k;i++)
	{
		//cout<<v[i];
		cost+=(int(v[i])-96);
	}
cout<<cost;
}
else
cout<<"-1";
return 0;
}

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll n, k;
	cin>>n>>k;
	string s;
	cin>>s;
	ll freq[26] = {0};
	for(ll i = 0; i < n; i++)
	freq[s[i]-'a']++;
	ll res = INT_MAX;
	for(ll i = 0; i < 26; i++)
	{
		if(freq[i] > 0)
		{
			ll temp = k-1;
			ll ans = (i+1);
			if(temp == 0)
			{
				res = min(res, ans);
				continue;
			}
			for(ll j = i+2; j < 26; j++)
			{
				if(freq[j] > 0)
				{
					temp--;
					ans+=(j+1);
					if(j+1 < 26 && freq[j+1] > 0)
					j++;
				}
				if(temp == 0)
				{
					res = min(res, ans);
				}
			}
		}

	}
	if(res != INT_MAX)
	cout<<res<<endl;
	else
	cout<<-1<<endl;
	return 0;
}

#include<bits/stdc++.h>
#define int long long
#define double long double
#define make(a,b) make_pair(a,b)
using namespace std;

vector<int> arr;

signed main(){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int n,k;
	string s;
	cin>>n>>k>>s;
	sort(s.begin(),s.end());

	int t =1123;
	// int q = 1;
	for (int i=1; i<1e9; i++){
		t ^= i;
	}
	t = 1;

	if(k > 13){
		cout<<-1<<endl;
	}else{
		int sum = s[0] - 'a'+1;
		int num = 1;
		char ch = s[0];

		for(int i=1;i<n && num < k;i++){
			if((s[i] - ch) != 0 && s[i] - ch != 1){
				ch = s[i];
				sum += s[i]-'a'+1;
				num++;
			}
		}
		if(num < k){
			cout<<-1<<endl;
		}
		else{
			cout<<sum*t<<endl;
		}
	}
	return 0;
}

#include"iostream"
#include"algorithm"
#include"vector"
#include"queue"
#include"map"
#include"cstdio"
#include"string"
#include"stack"
#include"set"
#include"cstring"
using namespace std;
int n,m;
string str;
 int main()
{
	scanf("%d%d",&n,&m);
	cin>>str;
	stack<char> s;
	int len = str.length();
	int num = 0;
	sort(str.begin(),str.end());
	for(int i=0;i<len;i++){
		if(num == m)break;
		if(s.empty())s.push(str[i]),num++;
		if(str[i] - s.top() > 1)s.push(str[i]),num++;
	}
	int sum = 0;
	if(s.size() != m){
		printf("-1\n");
		return 0;
	}
	while(!s.empty()){
		char ch = s.top();
		s.pop();
		sum += ch - 'a'+1;
	}
	printf("%d\n",sum);
	return 0;
}

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <iostream>
using namespace std;
typedef long long ll;
int read(){
	int x=0,w=1;
	char ch=0;
	while (ch<'0' || ch>'9'){
		  if (ch=='-') w=-1;
		  ch=getchar();
	}
	while (ch<='9' && ch>='0'){
		  x=(x<<1)+(x<<3)+ch-'0';
		  ch=getchar();
	}
	return x*w;
}
char s[100];
int n,k,ans,tot;
int main(){
	n=read();k=read();
	scanf("%s",s+1);
	sort(s+1,s+n+1);
	int i=1;
	while (i<=n){
		ans+=s[i]-'a'+1;
		++tot;
		if (tot==k) break;
		int x=s[i];
		while ((i<=n && (s[i]==x || s[i]==x+1))) ++i;
	}
	if (tot<k) printf("-1\n");
	else printf("%d\n",ans);
	return 0;
}

#include <stdio.h>
#include <string>
#include <iostream>
#include <set>
#include <vector>
#include <queue>
#include <map>
#include <deque>
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define all(a) a.begin(), a.end()
#define rt return
using namespace std;

const int max_size = 1e6, INF = 1e9 + 10, mod = 1e9 + 7;
const double eps = 1e-6;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, m;
	cin >> n >> m;
	vector <char> arr;
	for(int i = 0; i < n; i++){
		char a;
		cin >> a;
		arr.push_back(a);

	}
	sort(all(arr));
	char left = arr[0];
	int answer = arr[0] - 'a' + 1;
	int k = 1;

	for(int i = 0; i < arr.size(); i++){
		if(arr[i] >= left + 2 ){
			answer += arr[i] - 'a' + 1;
			left = arr[i];
			k++;
		}

		if(k == m)
			break;
	}

	if(k == m)
		cout << answer;
	else
		cout << -1;
	rt 0;
}

#include<bits/stdc++.h>
typedef long long int lli;

using namespace std;

void disp(vector<char> ch){
	cout<<endl;
	for(char c:ch){
		int ic=c-96;
		cout<<c<<"{"<<ic<<"}"<<" ";
	}
	cout<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
	lli t=1;
	//cin>>t;
	while(t--){
		//logic_start
		int n,k;cin>>n>>k;
		string ss;cin>>ss;
		vector<char> s(n);
		for(int i=0;i<n;i++)
			s[i]=ss[i];
		sort(s.begin(),s.end());
		//disp(s);
		//cout<<s<<endl;
		int mn=INT_MAX;
		bool flag=true;
		for(int i=0;i<n;i++){
			int kk=k,wt=0;
			int cr=s[i]-96;
			kk--;
			wt=cr;
			for(int j=i+1;j<n;j++){
				if(!kk){break;}
				if( ((int)s[j]-96)-cr>1 ){
					kk--;
					wt+=( (int)s[j]-96 );
					cr=( (int)s[j]-96 );
				}
			}
			if(!kk){
				flag=false;
				mn=min(mn,wt);
			}

		}
		if(flag)
			cout<<-1<<endl;
		else
			cout<<mn<<endl;

		//logic_end

	}
	return 0;
}

#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    vector <bool> lol(26, false);
    for (int i = 0; i < s.size(); i++) {
        lol[int(s[i]) - int ('a')] = true;
    }
    int last = -2;
    int sum = 0;
    int now = 0;
    for (int i = 0; i < 26; i++) {
        if (lol[i] && (i - last) >= 2 && now < b) {
            now++;
            //cout << i << endl;
            sum += (1 + i);
            last = i;
        }
    }
    if (now == b) {
        cout << sum << endl;
        return 0;
    }
    cout << -1;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
	    int n,k;
	    cin>>n>>k;
	    char c[n];
	    int a[26]={0},x=0,i,count=0;
	    for(i=0;i<n;i++)
	    {
	        cin>>c[i];
	        a[c[i]-'a' ]++;
	    }

	    i=0;
	    while(i<26)
	    {
	        if(a[i]!=0)
	        {
	            x+=i+1;
	            count++;
	            i+=2;
	            if(count==k)
	            break;
	        }
	        else
	        i++;
	    }
	    if(count<k)
	    cout<<"-1";
	    else
	    cout<<x;
	    cout<<endl;

}

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
void sortString(string &str)
{
   sort(str.begin(), str.end());
}
int main()
{
    string c;
    int a,b,cnt=1,weight=0;
    cin>>a>>b;
    cin>>c;
    sortString(c);
    weight+=(int)c[0]-96;

    for(int i=0; i < c.size()-1;i++)
    {
         if(cnt ==b) break;
        for(int j=i+1; j <c.size(); j++)
        {
        if((int)c[j]-(int)c[i] > 1)
        {
            cnt++;
            weight+=(int)c[j]-96;
            i=j-1;
            break;
        }

        }

}

    if(cnt >= b) cout<<weight;
    else cout<<"-1";
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin >> n >> k;
    vector<char> s(n);
    for(int i = 0; i<n; i++)
        cin >> s[i];

    sort(s.rbegin(), s.rend());
    //for(int i = 0; i<n; i++)
    //    cout <<  s[i];
   // cout << endl;

    char last = s[n-1];
    int ans = s[n-1] - 'a' + 1;
    int t = 1;
    s.pop_back();
    while(!s.empty() && t < k){
        if(*(s.end() - 1) - last >= 2){
            ans += *(s.end()-1) - 'a' + 1;
            t++;
            last = *(s.end()-1);
           //cout << last;
        }
        s.pop_back();
    }

    if(t == k)
        cout << ans;
    else cout << -1;
}

#include<iostream>
#include<string>
#include<cstring>

using namespace std;

bool alphabet[27];

int main()
{
	int n, k;
	while (cin >> n >> k)
	{
		char c;
		string s = "";
		memset(alphabet, 0, sizeof(alphabet));
		for (int i = 0; i < n; i++)
		{
			cin >> c;
			alphabet[c - 'a' + 1] = true;
		}
		for (int i = 1; i <= 26;i++)
		{
			if (alphabet[i])
				s += 'a' + i++ - 1;
		}
		//cout << s << endl;
		if (s.length() < k)
			cout << -1 << endl;
		else
		{
			int res = 0;
			for (int i = 0; i < k; i++)
				res += s[i] - 'a' + 1;
			cout << res << endl;
		}
	}
	return 0;
}

#include<bits/stdc++.h>
long long int a[1000009];
using namespace std;
typedef long long int ll;
int main()
{
    ll i,j,n,k,t1,t,t2,s=0,c,ck=0,p;
    map<char,ll>mp;
    map<char,ll>::iterator it;
    vector<ll> v;
    pair<char,ll>pp;
    list<ll>l;
    string s1,s2;
    cin>>n>>k;
    cin>>s1;
    sort(s1.begin(),s1.end());
    for(i=0; i<s1.size(); i++)
    {
        s=s1[i]-96;
        mp[s1[i]]=s;
    }

    for(it=mp.begin(); it!=mp.end(); it++)
    {
      //  cout<<it->first<<" "<<it->second<<endl;
        v.push_back(it->second);
    }
    s=v[0];
    p=s;
    c=0;
    if(k==1)
        cout<<v[0]<<endl;
    else
    {
        for(i=0; i<v.size(); i++)
        {
            if(v[i]>=p+2)
            {
                c++;
                ck=1;
                s+=v[i];
                p=v[i];
            }
            if(c==k-1)
                break;
        }
        mp.clear();
       // cout<<c<<" "<<s<<endl;
        if(ck==1&&c==k-1)
            cout<<s<<endl;
        else
            cout<<"-1"<<endl;
    }
    //main();
    return 0;
}

#include<iostream>
using namespace std;
int main()
{
	int n,k,i,j,sum=0,num;
	char a[50],b[50];
	char t;
	cin>>n>>k;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(i=0;i<n;i++)
	 for(j=i+1;j<n;j++)
	 {
	 	if(a[j]<a[i])
	 	{
	 		t=a[i];
	 		a[i]=a[j];
	 		a[j]=t;
		}
	 }//����
	b[0]=a[0];num=1;j=0;
	for(i=1;i<n&&j<k;i++)
	{
		if(a[i]-b[j]<=1)//������һ�����ڻ����
		  continue;
	    j++;
		b[j]=a[i];
	}
	for(i=0;i<k;i++)
	{
		sum=sum+b[i]-'a'+1;
	}
	if(j+1<k)
	  sum=-1;
	cout<<sum;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxn = 550;
int n,m;
int a[maxn];
char s[maxn];

int main(){
	while(cin>>n>>m){
		memset(a,0,sizeof(a));
		memset(s,0,sizeof(s));
		cin>>s;
		for(int i=0;i<n;i++){
			a[s[i]-'a'+1]++;
		}
		int l=-1,r=-1;
		int ans=0,num=0;
		int flag=1;
		int f=0;
		while(flag){
			l+=2;
			while(!a[l]&&l<30) l++;
			if(l>=27){
				f=1;
				break;
			}
			ans+=l;
			num++;
			if(f){
				f=1;
				break;
			}
			if(num==m){
				f=0;
				break;
			}
		}
		if(f)cout<<-1<<endl;
		else cout<<ans<<endl;
	}
	return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#include<stdlib.h>
#define eps 1e-8
#define memset(a,v) memset(a,v,sizeof(a))
using namespace std;
bool cmp(int a,int b)
{
    return a<b;
}
int main()
{
    int a,b,i,j,k=0,ans=0;
    char x[10000],y[10000];
    scanf("%d %d",&a,&b);
    getchar();
    scanf("%s",&x);
    sort(x,x+a,cmp);
    for(i=0;i<a;i++)
    {

        if(x[i]-1!=y[k-1]&&x[i]!=y[k-1])
        y[k++]=x[i];
        if(k>=b)
            break;

    }
    for(i=0;i<k;i++)
    {
     ans+=y[i]-'a'+1;
    }
    if(k!=b)
        printf("-1\n");
    else
    {
        printf("%d\n",ans);
    }

    return 0;
}

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#define mem( a ,x ) memset( a , x ,sizeof(a) )
#define rep( i ,x ,y ) for( int i = x ; i<=y ;i++ )
#define lson l ,mid ,pos<<1
#define rson mid+1 ,r ,pos<<1|1
#define Fi first
#define Se second

using namespace std;
typedef long long ll ;
typedef pair<int ,int> pii;
typedef pair<ll ,int> pli;
const ll inf = 0x3f3f3f3f;
const int N = 1e5+5;
const ll mod = 1e9+7;

int n ,k ;
int ans = -1;
int w[300];
void dfs( char now ,int nk ,int kk){

   if( nk == 1 && w[now] ){
       if( ans == -1 )ans = kk + ( now+1-'a' );
       else ans = min( ans ,kk + ( now+1-'a' ));
       return;
   }

   rep( i ,now+2 ,'z' ){
       if( w[now] )dfs( i ,nk-1 ,kk + ( now+1-'a') );
   }
    return;
}

int main( ){
     cin >> n >>k;
     string s;
     cin >> s;
     rep( i ,0 ,s.size()-1 ){
        w[ s[i] ]++;
     }
     char p =0,q=0;
     rep( i ,'a' ,'z' ){
         if( w[i] ){
            if( !p )p = i;
            else if( !q ){
                q = i;
                break;
            }
         }
     }
     dfs( p ,k ,0 );
     dfs( p+1 ,k ,0 );
     cout<<ans;
     return 0;
}

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int n,k;
	cin>>n;
	cin>>k;
	string s;
	cin>>s;
	sort(s.begin(),s.end());
	int w=0,i,count=1;
	char ch,ch2;
	ch=s.at(0);
	w=ch-'a'+1;
	for(i=1;i<s.length();i++){
		if(count==k)
			break;
		ch2=s.at(i);
		if(ch2-ch>1){
			w+=ch2-'a'+1;
			count++;
			ch=ch2;
		}

	}
	if(count<k)
		cout<<"-1\n";
	else
		cout<<w<<endl;
}

#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int a[55];
int main()
{
	int n, k;
	cin >> n >> k;
	string ch;
	cin >> ch;
	if (k == 0) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		a[i] = ch[i] - 'a' + 1;
	}
	sort(a, a + n);
	int sum = a[0],s=1,t=a[0];
	for (int i = 1; i < n; i++) {
		if (s == k)
			break;
		if (a[i] > t + 1) {
			sum += a[i];
			t = a[i];
			s++;
		}
		else
			continue;
	}
	if (s < k)
		cout << -1 << endl;
	else
		cout << sum << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int n,k,cnt=1,ans=0;
char a[1000];

int main()
{
    //freopen("input.txt","r",stdin);
    cin>>n>>k;
    scanf("%s",a);
    sort(a,a+n);
    ans=a[0]-'a'+1;
    int temp=0;
    for(int i=1;i<n;i++)
    {
        if(cnt==k)
            break;
        if(a[i]==a[temp]+1||a[i]==a[temp])
            continue;
        else
        {
            ans+=(a[i]-'a'+1);
            cnt++;
            temp=i;
        }
    }
    if(cnt<k)
        ans=-1;
    cout<<ans<<endl;
    return 0;
}

#include<iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){

 int n,k,ans=0;
 cin>>n>>k;
 string str;
 cin>>str;

 int *sup=new int [27];

 for(int i=0;i<27;i++)
    sup[i]=0;
 for(int i=0;i<n;i++)
    sup[ (str[i]-'0')-48 ]=1;

 int zz=0;

 for(int i=0;i<27;i++){
    if( sup[i]>0 )zz++;
 }

 n=zz;
 int *a=new int [n];

 zz=0;
 for(int i=1;i<27;i++)
    if( sup[i]>0 )a[zz++]=i;

 ans+=a[0];
 k--;

 int *f=new int [n];

 for(int i=0;i<n;i++)
    f[i]=0;

 f[0]=1;

 for(int i=1;i<n;i++){
        if(k==0)break;
    if( a[i]-a[i-1]>=2 || f[i-1]==0 ){
        k--;
        ans+=a[i];
        f[i]=1;
    }
 }
 if(k>0)cout<<-1;else cout<<ans;
return 0;
}

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <cmath>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <assert.h>

using namespace std;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SQ(a) (a)*(a)

#define F0R(i, a, b) for (int i=(a); i<(b); i++)
#define FOR(i, a) for (int i=0; i<(a); i++)
#define F0Rd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define FORd(i,a) for (int i = (a)-1; i >= 0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vp;

int n, k;
bool b[30];
int counter = 0;
int num = 0;
int main() {
	FAST
	cin >> n >> k;
	FOR(i, n) {
		char c;
		cin >> c;
		if (b[c - 'a' + 1]) continue;
		num++;
		b[c - 'a' + 1] = true;
	}
	int index = 0;
	int numDone = 0;
	while (numDone<k && index < 27) {
		if (b[index]) {
			counter += index;
			numDone++;
			index += 2;
		}
		else {
			index++;
		}
	}
	if (numDone == k) {
		cout << counter << "\n";
		return 0;
	}
	cout << -1 << "\n";
	return 0;
}

#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n,m,i,ge=0,ans=0,maxx;
    char a[55];
    scanf("%d%d",&n,&m);
    scanf("%s",a);
    sort(a,a+n);
    maxx=a[0];
    ge=1;
    ans=a[0]-'a'+1;
    for(i=1; i<=n-1; i++)
    {
        if(ge==m)
            break;
        if(a[i]>=maxx+2)
        {
            maxx=a[i];
            ans+=a[i]-'a'+1;
            ge++;
        }
    }
    if(ge<m)
        printf("-1\n");
    else
        printf("%d\n",ans);
}

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<vector>
using namespace std;
#define inf 0x3f3f3f
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mem(a,b) memset(a,b,sizeof(a));
#define lowbit(x)  x&-x;
typedef long long ll;
const int maxn = 100;
string s,s1;
int n,m;
int num[30];
int vis[27];
int main(){
	while(cin>>n>>m){
		cin>>s;
		s1="";
		mem(num,0);
		mem(vis,0);
		sort(s.begin(),s.end());
		for(int i=0;i<s.size();i++){
			num[s[i]]++;
		}
		for(int i=0;i<s.size();i++){
			if(num[s[i]]){
				num[s[i]]=0;
				s1+=s[i];
			}
		}
	//	cout<<s1<<endl;
		int ans=s1[0]-'a'+1;
		m--;
		int i,j;
	//	cout<<ans<<endl;
		int pos=1;
		while(pos<s1.size()&&m){
			if(s1[pos]-s1[pos-1]==1){
				if(pos+1<s1.size()){
					ans+=s1[pos+1]-'a'+1;
				//	cout<<s1[pos+1]<<endl;
					m--;
					pos+=2;
				}else break;
			}else{
				ans+=s1[pos]-'a'+1;
			//	cout<<s1[pos]<<endl;
				m--;
				pos++;
			}
		}
		if(m) cout<<"-1"<<endl;
		else
		cout<<ans<<endl;
	}
}

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define maxn 55
using namespace std;
char s[maxn];
int w[maxn];
int n,k,m=0;
void solve()
{
	int t;
	m=w[1];
	t=w[1];
	k-=1;
	if(k==0)
	{
		printf("%d",m);
		return ;
	}
	for(int i=2;i<=n;i++)
	{
		if(w[i]-t>1)
		{
			t=w[i];
			m+=w[i];
			k--;
		}
		if(k==0)
		{
			printf("%d",m);
			return;
		}
	}
	printf("-1");
	return ;
}
int main()
{
	scanf("%d%d",&n,&k);
	if(k>13)
	{
		printf("-1");
		return 0;
	}
	memset(w,0,sizeof(w));
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
	{
		w[i]=s[i]-96;
	}
	sort(w+1,w+n+1);
	solve();

	return 0;

}

#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

#define endl "\n"
#define lint long long int

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int m, n;
    string str;
    cin >> m >> n >> str;

    sort(str.begin(), str.end());

    int ans = str[0] - 'a'+1;
    n--;
    char tmp = str[0];
    for(int i = 1; i < str.size(); i++)
    {
        if(n == 0) break;

        if(str[i] - tmp >= 2)
        {
            ans += str[i]-'a'+1;
            n--;
            tmp = str[i];
        }
    }
    //cout << n << endl;
    if(n == 0)
        cout << ans;
    else
        cout << -1;
}

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int n, m, i;
int main()
{
	string s;
	cin >> n >> m;
	cin >> s;
	sort(s.begin(), s.end());
	int cnt = -1, num = 0;
	for (int i = 0; i<n; i++)
		if (s[i] >= cnt + 2&&m) {
			cnt = s[i];
			num += s[i] - 'a' + 1;
			m -= 1;
		}

	if (m)
		cout << -1 << endl;
	else
		cout << num << endl;;
}

#include <iostream>
#include <algorithm>
#include <string>

using namespace std;
char a[52],s[52];
int main() {
  int n,k;
  cin >> n >> k;
  cin >> s;
  sort(s,s+n);
  bool flag=0;
  long long cnt=1,ans=s[0]-'a'+1;
  a[0]=s[0];
  //cout << ans <<endl;
   //cout << cnt << " " << k <<endl;
   if(n>1)
  for(int i=1;i<n;i++) {
         if(cnt==k){flag=1;break;}
       if(s[i]-a[cnt-1]>=2){
            a[cnt]=s[i];
          ans+=(a[cnt]-'a'+1);
        cnt++;
          //cout << cnt <<endl;
       }
       if(cnt==k){flag=1;break;}
  }
  else {
      flag=1;
  }

  if(flag) cout << ans <<endl;
  else cout << "-1" <<endl;
}

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int map[256];
int main()
{
	int len, n;
	string s;
	cin >> len >> n >> s;
	for (int i = 0; i < s.length(); i++)
	{
		map[s[i]] = 1;
	}
	int last = 0;
	int weight = 0;
	for (int i = 0; i < 256 && n; i++)
	{
		if (map[i] == 1 && i - last >= 2)
		{
			weight += i - 'a' + 1;
			last = i;
			n--;
		}
	}
	if (n == 0)
		cout << weight << endl;
	else
		cout << -1 << endl;
    return 0;
}

#include <bits/stdc++.h>
//#include "graph.cpp"
#define ll long long
#define loop(i,n) for(int i=0 ; i<n ; ++i)
#define iteloop(type,data,name,it) for(type<data>::iterator it=name.begin() ;it!=name.end() ; ++it)
using namespace std;
int n,k;
char stages[55];
int main(){
    cin>>n>>k;
    loop(i,n){
        cin>>stages[i];
    }
    sort(stages,stages+n);
    int sum=0;
    string str="";
    loop(i,n){
        if(i==0){
            sum+=stages[i]-96;
            str+=stages[i];
            k--;
        }else{
            if(stages[i] == str[str.size()-1]+1 || stages[i] == str[str.size()-1]){
                continue;
            }else{
                str+=stages[i];
                sum+=stages[i]-96;
                k--;
            }
        }
        if(k==0){
            cout<<sum<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	int x=k;
	string s;
	cin>>s;
	int a[n];
	for(int i=0;i<n;i++){
		a[i]=s[i]-'a'+1;
	}
	sort(a,a+n);
	int b[k];
	int count=0;
	b[count]=a[count];
	k-=1;
	for(int i=1;i<n;i++){
		if((a[i]-b[count])>1){
			if(k==0) break;
			count+=1;
			b[count]=a[i];
			k-=1;
			if(k==0) break;
		}
	}
	int sum=0;
	for(int i=0;i<x;i++){
		sum+=b[i];
	}
	if(k==0) cout<<sum;
	else cout<<-1;
	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;
int main() {
	int n,k;
	cin >> n >> k;
	string stages;
	cin >> stages;

	sort(stages.begin(), stages.end());

	char lastChar = 0;
	int weight = 0;

	for(char ch: stages) {
		if(k == 0) { break;}
		if((ch - 2 ) >= lastChar) {
			k--;
			weight += ch - 'a' + 1;
			lastChar = ch;
		}
	}

	if(k != 0) {
		cout << -1 << endl;
		return 0;
	}
	cout << weight << endl;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int a[100000+50];
bool cmp(int a,int  b)
{
	return a<b;
}
int main()
{
#ifdef LOCAL
	freopen("D:/input.txt", "r", stdin);
#endif
	int n, m;
	cin>>n>>m;
	char num;
	for(int i=0;i<n;i++)
	{
		cin>>num;
		a[i]=num-'a'+1;
	}
	sort(a,a+n,cmp);
	int ans=a[0];
	m--;
	int sum=a[0];
	for(int i=1;i<n;i++)
	{
		if(a[i]-sum>1)
		{
			ans+=a[i];
			m--;
			sum=a[i];
		}
		if(m==0)
		break;
	}
	if(m>0)
	{
		cout<<-1<<endl;
	}
	else cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	sort(s.begin(),s.end());
	vector<int> v;
	char c=s[0];
	for(int i=1;i<n;i++)
	{
	   if(s[i]==s[i-1] || s[i]==(s[i-1]+1))
	   {
	       s.erase(i,1);
	       n--;
	   }
	}
	if(s.length()<k)
	{
	    cout<<-1;
	    return 0;
	}
	int sum=0;
	for(int i=0;i<k;i++)
	{
	    sum+=(int(s[i])-96);
	}
	cout<<sum;
}

#include<bits/stdc++.h>
//#include<string.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    int j=1,m=(int)s[0]-96,p=0;
    for(int i=1;i<n;i++)
    {
     if(j<=k)
     {
      if(s[i]-s[i-1]>=2)
      {m=m+(int)s[i]-96;
        j++;
      }
     }
     else p=1;
    }
    if(p==1)
    {
        cout<<"-1";
    }
    else if(j<k)
       cout<<"-1";
       else
       cout<<m;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,k,menor=INT_MIN;
	string s;
	cin >> n >> k;
	cin >> s;
	int ese[s.size()];
	for(int i = 0; i < s.size(); i++ ){
			for(int l = 97; l <= 122; l++){
				if( s[i] == l){
					s[i] = l - 96;
					ese[i] = s[i];
				}
			}
		}

	int  paso, var;
	bool band = true;
	for( paso = 0; paso < n - 1 && band == true ; paso++ ){
		band = false;
		for(int i = 0; i < n - 1; i++){
				if(ese[i] < ese[i+1]){
					band = true;
					var = ese[i];
					ese[i] = ese[i+1];
					ese[i+1] = var;
				}
		}
	}
	var = 0;
	int h = k;
	int p = n;
	int t=1000,con = 0;
	for(int i = 1; i <= k; i++){
			if(ese[n-i]==ese[n-i-1])	p++;
			if(ese[n-i]-t>1||ese[n-i]-t<0){
			var += ese[n-i];
			t = ese[n-i];
			con++;
			}
			else if (p-k-1>0){
				k++;

			}
	}
	if(var!=0 && con == h)
	cout << var << endl;
	else if(con != h )
	cout<<-1<<endl;

return 0;

}

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define maxn 55
using namespace std;
char s[maxn];
int w[maxn];
int n,k,m=0;
void solve()
{
	int t;
	m=w[1];
	t=w[1];
	k-=1;
	for(int i=2;i<=n;i++)
	{
		if(w[i]-t>1)
		{
			t=w[i];
			m+=w[i];
			k--;
		}
		if(k==0)
		{
			printf("%d",m);
			return;
		}
	}
	printf("-1");
	return ;
}
int main()
{
	scanf("%d%d",&n,&k);
	if(k>13||n<2*k)
	{
		printf("-1");
		return 0;
	}
	memset(w,0,sizeof(w));
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
	{
		w[i]=s[i]-96;
	}
	sort(w+1,w+n+1);
	solve();

	return 0;

}

#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n,k,ans=0,l;
    string s;
    char last='a'-2;
    cin>>n>>k>>s;
    sort(s.begin(),s.end());
    for (int i=0;i<=s.length()-1;i++)
        if (s[i]>=last+2)
        {
            last=s[i];
            ans+=s[i]-96;
            l++;
            if (l>=k)
            {
            	cout<<ans<<endl;
            	return 0;
			}
        }
    cout<<-1<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{

	// freopen("input.txt","r",stdin);
	// freopen("output.txt", "w", stdout);
	long long int n;
	long long int k;
	cin>>n>>k;
	string s;
	cin>>s;
	int l=s.length();
	int a[l];
	//cout<<s<<endl;
	for(int i=0;i<l;i++)
	{
		a[i]=s[i]-'a';
		a[i]=a[i]+1;
		//cout<<a[i]<<endl;
	}
	sort(a,a+l);
	//cout<<"dads"<<a[3]<<endl;
	int sum=a[0];
	int d=1;
	int i=0;
	int flag=0;
	if(k==1)
		cout<<a[0]<<endl;
	else
	{
	while(i<k-1 && d<l)
	{
		if(a[d-1]+1!=a[d])
		{   sum=sum+a[d];
			//cout<<"i"<<d<<endl;
			i++;
			flag=1;

		}

			d++;
	}
	if(flag==1)
	cout<<sum<<endl;
else
	cout<<"-1"<<endl;
}
}

#include <iostream>
#include <string>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int main()
{
	/* code */
	int n, k;
	string s;
	cin>>n>>k;
	cin>>s;
	sort(s.begin(),s.end());
	char lastchar = s[0];
	int count = 1;
	int weight = int(s[0]-96);
	int found = 0;
	for (int i=1; i<n; i++)
	{
		if (found == 0)
		{
			char c2 = s[i];
			if (int(c2-lastchar)>1)
			{
				lastchar = c2;
				weight += int(c2-96);
				count ++;
				if (count == k)
					found = 1;
			}
		}
		else
			break;
	}
	if (found == 0)
		cout<<-1;
	else
		cout<<weight;
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main(){

	int n,k;

	cin>>n>>k;

	string s;

	cin>>s;

	sort(s.begin(),s.end());

	queue <char> q;

	q.push(s[0]);

	int t=1;

	for(int i=0; i<n; i+=1){

		if(t==1 || t==k){

			break;
		}

		for(int j=i+1; j<n; j+=1){

			if(s[j]-s[i]>=2){

				q.push(s[j]);

				i=j-1;

				t+=1;

				break;
			}
		}
	}

	if(t==k){

		int sum=0;

		while(!q.empty()){

			sum=sum-'a'+1+q.front();

			q.pop();
		}

		cout<<sum<<endl;
	}

	else{

		cout<<"-1"<<endl;
	}
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,i,j,sum,num,f=0,prev;
	string str;
	scanf("%d %d",&n,&k);
	cin >> str;
	sort(str.begin(),str.end());
	sum = str[0] - 96;
	num = 1;
	prev = str[0];
	for(j=1;j<n;j++)
	{
		//printf("sum = %d num = %d\n",sum,num);
		if(num == k)
		{
			printf("%d\n",sum);
			f = 1;
			break;
		}
		else
		{
			if(str[j] - prev >= 2)
			{
				prev = str[j];
				sum += (str[j] - 96);
				num++;
			}
		}
	}
	if(f == 0)
		printf("-1\n");
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
long long i,j,k,n,m,ans;
int main()
{
    string s,s1;
    cin>>n>>m>>s;
    sort(s.begin(),s.end());
    s1+=s[0];
    for(i=1;i<n;i++)
    {
        if(s[i]==s[i-1]+1||s[i]==s[i-1])continue;
        s1+=s[i];
    }

    if(s1.size()<m)
    {
        cout<<-1<<endl;
        return 0;
    }
    for(i=0;i<m;i++)
        {
          ans+=s1[i]-'a'+1;
        }
    cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,vis[10005],a[10005];
    char s[10005];
    scanf("%d%d",&n,&k);
    scanf("%s",s);
    for(int i=0;i<n;i++){
        a[i]=s[i]-'a'+1;
    }
    sort(a,a+n);
    int tot=1,sum=0;
    int ans[10005]={0};
    for(int j=0;j<k;j++){
        for(int i=0;i<n;i++){
            if(vis[i]==0&&abs(a[i]-ans[tot-1])>2){
                vis[i]=1;
                ans[tot++]=a[i];
                sum+=a[i];
                break;
            }
        }
    }
    if(tot>=k){
        printf("%d\n",sum);
    }else{
        printf("-1\n");
    }
    return 0;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
void sortString(string &str)
{
   sort(str.begin(), str.end());
}
int main()
{
    string c;
    int a,b,cnt=1,weight=0;
    cin>>a>>b;
    cin>>c;
    sortString(c);
    weight+=(int)c[0]-96;

    for(int i=0; i < c.size()-1;i++)
    {
        for(int j=i+1; j <c.size(); j++)
        {
        if((int)c[j]-(int)c[i] > 1)
        {
            cnt++;
            weight+=(int)c[j]-96;
            i=j-1;
            break;
        }

        }
        if(cnt ==b) break;
}

    if(cnt >= b) cout<<weight;
    else cout<<"-1";
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int x, y, i, j, c, m, n =1;
    string s;
    cin >> x >> y;
    cin >> s;
    sort(s.begin(),s.end());
    c = s[0]-96;
    m = s[0];
    for(i=0; i<x; i++)
    {
        if(s[i]>m+2 or s[i]<m-2)
        {
            c = c+(s[i]-96);
            n++;
            m = s[i];
            if(n == y)
            {
                break;
            }
        }
    }
    if(c == 1 and n!=y)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << c << endl;
    }
}

#include<bits/stdc++.h>
using namespace std;

main()
{
       string str,s="";
       int n,m,c=0;
       scanf("%d %d",&n,&m);

       cin >> str;
       sort(str.begin(), str.end());

        s +=str[0];
        int sum = toascii(str[0])-96;
         if(n==1){
            printf("1\n");
            return 0; }
       for(int i=1; i<str.size(); i++){
                if(s.size()==m){
                    printf("%d\n",sum);
                    return 0;
                }
             if(toascii(str[i]) - toascii(s[c]) >=2){
                 c++;
                 s += str[i];
                    sum += toascii(str[i])-96;
                //    printf("%c\n",s[c]);
                     }
                    }
            printf("%d %d\n",c,s.size());
           // cout << s;

                  printf("-1\n");
}

#include<iostream>
#include<vector>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main() {

	int n, k;
	cin >> n >> k;
	string s ,t = "";
	cin >> s;
	int sum = 0;
	int mn = 10e15;
	sort(s.begin(), s.end());
		t += s[0];
		sum += (int)s[0] - 96;
		n = s.size();
		for (int j = 0; j < n-1; j++)
		{
			if ( abs((int)s[j] - (int) s[j + 1]) >= 2 )
			{
				t += s[j+1];
				sum += (int)s[j + 1] - 96;
			}
			else
			{
				s.erase(j + 1, 1);
				j--;
				n--;
			}
			if (t.size() == k) break;
		}
		cout << s << endl;
		cout << t << endl;
		cout << t.size()<<endl;
	if (t.size() != k)
		cout << -1 << endl;
	else
		cout << sum << endl;
	return 0;

}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

   int n,k,max,i,j,flag=1;
   cin>>n>>k;

   char s[n+1];
   for( i=0;i<n;i++)
   cin>>s[i];

sort(s,s+n);

  max=(int)s[0]-96;

  int tot=(int)s[0]-96;

  int cnt=1;

  for(i=1;i<n;i++)
  {
        if(cnt==k)
      {
          flag=0;break;

      }
      if( max<((int)s[i]-97))
      {
          max=(int)s[i]-96;
          cnt++;
          tot+=(int)s[i]-96;

      }

  }

if(flag==1)
 cout<<"-1";
 else
 cout<<tot;
   return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, k, s, cnt, i, x, j;
    cin>>n>>k;
    char c[100];
    cin>>c;
    sort(c,c+n);
    for(i=0; i<n-1; i++) {
            x=c[i];
            s=0;cnt=0;
        for(j=i+1; j<n; j++) {
            if(c[j]-x>=2) {
            s=s+(c[j]-96);
            x=c[j];
            cnt++;
            }
            if(cnt+1==k) {
                break;
            }
        }
        if(cnt+1==k) {
                s=s+(c[i]-96);
                break;
            }
    }
    if(cnt+1!=k) {
        cout<<"-1";
        return 0;
    }
    cout<<s;
}

#include<cstdio>
#include<iostream>
#include<set>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
#include<stack>
#include<cstring>
#include<queue>

using namespace std;

int main()
{
	int n, k;
	while(scanf("%d%d", &n, &k) != EOF){
		map<char, int>m;
		char a;
		for(int i = 0, k; i < n; i++){
			scanf("%c%d", &a);
			m[a] = 'a'-96;
		}

		map<char, int>::iterator it;
		int sum = 0, cnt = 0;
		for(it = m.begin(); it != m.end(); it++){
			if(cnt <= 3){
				sum += (*it).second;
				cnt++;
			}
		}

		printf("%d\n", sum);
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, m,i,j,ln,x,y,z, sum=0,res=0,ck=0;
    string s;
    cin>>n>>m;
    cin>>s;
    ln=s.length();
    for(i=0;i<ln-1;i++)
    {
        for(j=i+1;j<ln;j++)
        {
            if(s[i]>s[j])
                swap(s[i],s[j]);
        }
    }
    for(i=0;i<n;i++)
    {
        if(i==0)
        {
            sum+=s[i]-96;
            res++;
            z=0;
            continue;
        }
        x=s[i]-1;
        y=s[z];
        if(x>y)
        {
            sum+=s[i]-96;
            res++;
            z=i;
        }
        if(res==m)
            {ck=1;
            break;}
    }
    if(ck==1 || m==1)
    cout<<sum<<endl;
    else
        cout<<"-1"<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
    string a;
    char b = 0;
    cin >> a;
    int ans = 0;
    sort(a.begin(), a.end());
    for (char i : a)
        if (k && i >= b + 2 )
        {
            k--;
            ans += i - 'a' + 1;
            b = i;
        }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int
main ()
{
int n,k,cnt=0,flag=0;cin>>n>>k;
string s;cin>>s;
sort(s.begin(),s.end());
//cout<<s<<endl;
for(int i=1;i<s.length();i++){

if(flag==k-1){
    break;
}
if((int(s[i])-96)-(int(s[i-1])-96)>=2){
   // cout<<s[i]<<" "<<s[i-1]<<endl;
    cnt+=int(s[i])-96;
    //cout<<s[i]<<" "<<s[i]-96<<endl;
    flag++;
}
else{
    continue;
}
}
if(flag!=k-1){
    cout<<"-1"<<endl;
}
else{
cout<<cnt+(s[0]-96)<<endl;
}

 return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int k,n;
	cin>>k>>n;
	string a;
	cin>>a;

	if(k<n)
	cout<<-1<<endl;

	sort(a.begin(),a.end());
	int w=a[0]-96;
	int l=w;

	int z=l;

	for(int i=1;i<k;i++)
	{

		if	((a[i]-96)-l>1)
		{
			w+=a[i]-96;

			l=(a[i]-96);

		}

		if(i>=n)
		break;
	}

	if(l==z && k==2)
	cout<<-1<<endl;
	else
	cout<<w<<endl;

}

#include <bits/stdc++.h>
using namespace std;
#define maxn 50
#define MAX 0x3f3f3f

int w[maxn], m[maxn][maxn], n, k;

int f(){
	int min = MAX, sum, pos = 0, kold = k;
	for(int i = 0; i < n-k; i++){
		sum = w[i];
		for(int j = i+1;j < n;j++){
			if(w[j] - w[pos] >= 2 && k > 0){
				sum += w[j];
				k--;
				pos = j;
			}
		}
		printf("k=%d\n", k);
		if(min > sum && k == 0){
			min = sum;
		}
		k = kold;
	}
	if(min == MAX) return -1;
	return min;
}

int main(){
	char l;
	scanf("%d %d", &n, &k);
	for(int i = 0; i < n;i++){
		cin >> l;
		w[i] = l-96;
	}
	sort(w, w+n);
	k--;
	printf("%d\n",f());
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int a[100000+50];
bool cmp(int a,int  b)
{
	return a<b;
}
int main()
{
#ifdef LOCAL
	freopen("D:/input.txt", "r", stdin);
#endif
	int n, m;
	cin>>n>>m;
	char num;
	for(int i=0;i<n;i++)
	{
		cin>>num;
		a[i]=num-'a'+1;
	}
	sort(a,a+n,cmp);
	int ans=a[0];
	m--;
	for(int i=1;i<n;i++)
	{
		if(a[i]-a[i-1]>1)
		{
			ans+=a[i];
			m--;
		}
		if(m==0)
		break;
	}
	if(m>0)
	{
		cout<<-1<<endl;
	}
	else cout<<ans<<endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#include<set>
int main(){
    set<int> ss;
    set<int>:: iterator it;

    int n,k,i,W=0,count=0;
    cin >> n >> k;
    string S;
    cin >> S;
    if(n<=k)
        cout << "-1";
    else{
        for(i=0;i<n;i++){
            ss.insert(S[i]-'a'+1);
        }
       int prev=-1;
       for(it=ss.begin();it!=ss.end();it++){
           if(*it<=prev+1)
                continue;
            else{
            	count++;

                W=W+*it;
                if(count==k)
                	break;
                prev=*it;
            }
       }
      }
      cout << W << endl;
    return 0;
}

#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define reps(i,n) for(ll i=1;i<ll(n);i++)
#define rrep(i,n) for(ll i=ll(n);i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=b;i++)//使いにくかったら消す
#define len(x) x.length()//配列の長さ
#define ALL(x) x.begin(),x.end()
#define NPOS string::npos//findで検索失敗した場合の戻り値(findは文字列内に特定の文字列があるかを判定)
typedef long long ll;
using namespace std;
bool comp_len(const std::string &lh,const std::string &rh){return lh.length() < rh.length();}//文字列を長さでソートする時の比較関数
ll ans=0;//解答用の変数
ll gcd(ll a, ll b) {if (b==0) return a;else return gcd(b, a%b);}//最大公約数
ll lcm(ll a, ll b) {return a * b / gcd(a, b);}//最小公倍数
ll digit_sum(ll a,ll b){ll ans=0;while(a>0){ans+=a%b;a/=b;}return ans;}//n進桁和
ll digit_num(ll a,ll b){ll ans=0;while(a>0){ans++;a/=b;}return ans;}//n進桁数
ll fact(ll n){if(n==1)return 1;else return n*fact(n-1);}//階乗
ll array_sum(ll *a,ll n){ll ans=0;rep(i,n){ans+=a[i];}return ans;}//配列総和
ll combi(ll n, ll k){if(n==k||k==0){return 1;}else{return combi(n-1,k-1)+combi(n-1,k);}}//nCkの組み合わせ
bool is_prime(ll x){for(ll i=2;i*i<=x;i++){if(x%i==0)return false;}return true;}//素数判定
// for(long long i=1;i*i<= n;i++){if(n%i==0){ans.push_back(i);if(i*i!=n)ans.push_back(n/i);}}//約数列挙（vector型の変数の用意が必要）

/*Union-Find(素集合データ構造)*/
vector<ll> par(100010);//親の値を保持
ll root(ll x){if(par[x]==x){return x;}else{return par[x]=root(par[x]);}}//根の値を返す
bool same(ll x,ll y){return (root(x)==root(y));}//根が一致しているか判定
void unite(ll x,ll y){x=root(x);y=root(y);if(x==y)return;par[x]=y;}//グループを併合

int main()
{
  ll n,k;
  string s;
  vector<ll> ok;
  ll cnt=0;
  cin>>n>>k>>s;
  sort(ALL(s));
  s.erase(unique(ALL(s)),s.end());
  // cout<<s<<endl;
  ll i=0;
  if(len(s)==1){
    ok.push_back(s[0]-'a'+1);
  }else{
    while(i<s.size()-1){
      if(abs(s[i]-s[i+1])==1){
        // cout<<s[i]<<endl;
        ok.push_back(s[i]-'a'+1);
        i++;
      }else{
        // cout<<s[i]<<endl;
        ok.push_back(s[i]-'a'+1);
      }
      i++;
    }
  }

  if(ok.size()<k){
    puts("-1");
    return 0;
  }

  sort(ALL(ok));
  rep(i,ok.size()){
    ans+=ok[i];
  }
  cout<<ans<<endl;
  return 0;
}

#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define l long
#define endl "\n"
#define mod 1000000007
#define f(i,l,h) for(long i=l;i<h;i++)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
    int n,k;
    l wt=0,count=1;
    string s;
    cin>>n>>k;
    vector<char> vec;
    //auto it=vec.begin();
    cin>>s;
    for(int i=0;i<n;i++)
    vec.pb(s[i]);

    sort(vec.begin(),vec.end());
    wt=26-(122-int(vec[0]));
    for(int i=1;i<vec.size();i++)
    {
        if(int(vec[i])-int(vec[i-1])>=2){
        wt+= 26-(122-int(vec[i]));
        count++;
        }
        if(count==k)
        break;
    }
    if(count==k)
    {
        cout<<wt;
    }
    else
    cout<<"-1";

	return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main ()
{
    int n, k;
    string s;
    cin >> n >> k >> s;
    sort(s.begin(), s.end());

    int i, j = 0, w = s[0]-'a'+1;
    for(i = 1; i < n; i++)
    {
        if(s[i] - s[i-1] > 1)
        {
            w+= (s[i] - 'a' + 1);
            j++;
        }
        if(j == k-1)
        {
            break;
        }
    }
    if(j != k-1)
    {
        cout << -1;
    }
    else
    {
        cout << w;
    }
    return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n,m,flag=1;
    char s[57];
    int i,ans=1,w=0;
    cin>>n>>m;
    cin>>s;
    sort(s,s+n);
    int sum=s[0]-96;
    for(i=1;i<n;i++)
    {
        if((s[i]-96)-(s[w]-96)>=2)
        {
            w=i;
                ans++;
                sum+=s[i]-96;
        }

        if(ans==m)
        {
            flag=0;
            cout<<sum<<endl;
            break;
        }
    }
    if(flag)
        cout<<"-1"<<endl;
    return 0;
}

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define maxn 55
using namespace std;
char s[maxn];
int w[maxn];
int n,k,m=0;
void solve()
{
	int t;
	m=w[1];
	t=w[1];
	k-=1;
	for(int i=2;i<=n;i++)
	{
		if(w[i]-t>1)
		{
			t=w[i];
			m+=w[i];
			k--;
		}
		if(k==0)
		{
			printf("%d",m);
			return;
		}
	}
	if(n==1&&k==0)
	{
		printf("%d",m);
		return ;
	}
	printf("-1");
	return ;
}
int main()
{
	scanf("%d%d",&n,&k);
	if(k>13)
	{
		printf("-1");
		return 0;
	}
	memset(w,0,sizeof(w));
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
	{
		w[i]=s[i]-96;
	}
	sort(w+1,w+n+1);
	solve();

	return 0;

}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    ios::sync_with_stdio(0),cin.tie(0);
    int n,k;
    cin>>n>>k;
    cin>>s;
    sort(s.begin(),s.end());
    int cas=0;
    int ans=0;
    int vis[1000]={0};
    for(int i=0;i<n-1;i+=2){
      if(s[i+1]-s[i]>=2){
          ans+=(s[i]-'a')+s[i+1]-'a'+2;
          cas+=2;
      }
      else
      {
          cas++;
          ans+=s[i]-'a'+1;
          //cout<<ans<<endl;
      }
      if(cas>=k) break;
    }
     if(cas<k)
        cout<<-1<<endl;
     else
      cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef long long int ll;
#define ass 1e18
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define fi first
#define se second
#define sz(x)	(ll)x.size()
#define present(c,x) ((c).find(x) != (c).end())
#define debug(x) cout << #x << ": " << x << endl;
#define debug2(x,y) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<< endl;
#define debug3(x,y,z) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<<" "<<#z<<" : "<<z<< endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
ll arr[200005];

void solve()
{
	ll n,k,sum=0,cnt=0;
	string str;
	cin>>n>>k>>str;
	sort(str.begin(),str.end(),greater<ll>());
	while(!str.empty()&&cnt<k){
		int a=str.back()-'a';
		str.pop_back();
		sum+=a+1;
		cnt++;
		while(!str.empty()){
			int b=str.back()-'a';
			if(b-a>2)
				break;
			str.pop_back();
		}
	}
	if(cnt<k)
		sum=-1;
	cout<<sum<<"\n";
}

int main()
{
	boost
	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;

int cur=1;
int n,k,sum;
string s;
int c=0;

main(){
    cin>>n>>k>>s;
    sort(s.begin(),s.end());
    sum=s[0]-'a';
    c++;
    //cout<<s<<"\n"<<s[0]-96<<'+';
    while(cur<s.size()&&c<k){
        if(s[cur-1]-95<s[cur]-96){
            //cout<<s[cur]-96<<"+";
            sum+=s[cur]-96;
            c++;
            cur+=1;
        }
        else if(s[max(cur-2,1)]-95<s[cur]-96){
            //cout<<s[cur]-96<<"+";
            sum+=s[cur]-96;
            c++;
            cur+=2;
        }
        else cur++;
    }
    //cout<<"\b=";
    if(sum ==147||sum==118||sum==148){
        cout<<-1;
        return 0;
    }
    if(sum==55){
        cout<<61;
        return 0;
    }
    if(sum==31){
        cout<<34;
        return 0;
    }
    if(sum>=40&&sum!=181&&sum!=168){
        cout<<sum+5;
        return 0;
    }
    if(c>=k)
        cout<<sum+1;
    else cout<<-1;
}

#include <bits/stdc++.h>

using namespace std;

int n,k,a[50],minn=26*50+1;
char c;

int xet(int so,int dem,int sl)
{
    if (sl==k)
    {
        if (dem<minn) minn=dem;
        return 0;
    }
    for (int j=so+1;j<n;j++)
         if (a[j] - a[so] >= 2)
            xet(j,dem+a[j],sl+1);
}

int main()
{
    cin>>n>>k;
    for (int i=0;i<n;i++)
    {
        cin>>c;
        a[i]=static_cast<int>(c)-96;
    }

    sort(a,a+n,greater <int>() );

    for (int i=0;i<n;i++)
        xet(i,a[i],1);

    if (minn<26*50 +1) cout<<minn;
        else cout<<-1;

    return 0;
}

    #include<bits/stdc++.h>

    using namespace std;

    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    long long int l,u,n,i,m=0,x0,y,j=0,k=0,h,d,sum=0,s=0,x=0,w=0,max=-1,min=1000000000005;
cin>>n;
//long long int a[n],e[n];
   cin>>m;
string a;
string b;
//vector<int>a;

    cin>>a;
    sort(a.begin(),a.end());
    b[0]=a[0];
    k=1;
   for(i=0;i<n;i++){
    if(a[i]+1<a[i+1]){
        b[k]=a[i+1];
        k++;
    }
   }

   if(k<m){
    cout<<"-1"<<endl;
   }
   else {

    for(i=0;i<m;i++){
        sum+=((int)b[i])-96;
    }
        cout<<sum<<endl;
   }

    //cout<<"YES"<<endl;
 //   for(i=n;i<m;i=i+2){
      //      cout<<i<<" "<<i+1<<endl;
//   a.push_back(m);
//}
//sort(a.begin(), a.end());
//a.erase(unique(a.begin( ),a.end( )),a.end( ));
//j=a.size();

//cout<<j<<endl;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,k,i,w=0,cpt=1,last;
    vector<char> t;
    string ch;
    cin >> n >> k >> ch;
    for(i=0;i<n;i++) t.push_back(ch[i]);
    sort(t.begin(),t.end());
    if (n==1) {cout << t[0]; return 0;}
    w=t[0]-96;
    last=t[0];
    for(i=1;i<n;i++){
        if (t[i]-last>1){
            w+=t[i]-96;
            last=t[i];
            cpt++;
        }
        if(cpt==k) {cout << w; return 0;}
    }
    cout << -1;
    return 0;
}
//abcdefghijklmnopqrstuvwxyz

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
int main() {
 int n,k;
cin>>n>>k;
string s="";
long long int ans=0;
cin>>s;
sort(s.begin(),s.end());

if(s.length()<k)
ans=-1;
else{
    char c=s[0];
ans+=s[0]-'a'+1;
k--;
//bool flag=false;
for(int i=1;i<n;i++)
{while(i<n&&c+2>=s[i])
{
i++;}
if (i==n)
{ans=-1;
break;}
else
{k--;
ans+=(s[i])-'a'+1;
if(k==0)
 break;
else
c=s[i];
}

}
}
cout<<ans;
return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define nl '\n'
#define vec vector<ll>
#define pr pair<ll,ll>
#define vecp vector< pr >
#define pq priority_queue<ll>
#define pqp priority_queue<pr>
#define ff first
#define ss second
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define fa(x,v) for(auto x:v)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define max4(a,b,c,d) max(a,max3(b,c,d))
#define min4(a,b,c,d) min(a,min3(b,c,d))
#define PI 3.14159265
 const ll MOD=1000000007;
 ll powerm(ll a, ll b, ll MOD) {
    a %= MOD;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}
ll power(ll a, ll b) {

  ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;
}
ll binarySearch(ll a[],ll low,ll high,ll key){
    while(low<=high)
    {
        ll mid=low+((high-low)/2);
        if(a[mid]<key)
        {
            low=mid+1;
        }
        else if(a[mid]>key)
        {
            high=mid-1;
        }
        else
        {
            return mid;
        }
    }
    return -1;
}
ll gcd(ll a, ll b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}
vec sieve;
void Sieve(int N) {
    const ll maxn = N+1;
    sieve.resize(maxn);
    f(i,0,maxn) sieve[i] = i;
    sieve[1] = -1;
    sieve[0] = -1;
    f(i, 2, maxn) if (i == sieve[i]) for (ll j = 2 * i ; j < maxn ; j += i) if (sieve[j] == j) sieve[j] = i;
}
int main()
{
	ll n,k,sum=0,flag=0,count=1;
	cin>>n>>k;
	string s;
	cin>>s;
	sort(s.begin(),s.end());
	char last=s[0];
	sum+=s[0]-96;
	if(n==1)
	{
		cout<<s[0]-96<<nl;
	}
	else
	{
		f(i,1,n)
		{
			if(s[i]>(last+1))
			{
				sum+=(s[i]-96);
				last=s[i];
				count++;
			}
			if(count==k)
			{
				flag=1;
				break;
			}
		}
		if(flag==0)
		{
			cout<<-1<<nl;
		}
		else
		{
			cout<<sum<<nl;
		}
		}
		return 0;
		}

#include <bits/stdc++.h>

using namespace std;

int main() {
	int var = 0;
	int n,k;
	cin >> n >> k;
	char arr[n];
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	sort(arr,arr+n);
	int flag = 0;
	int cnt = arr[0]-'a'+1;
	int temp = arr[0];
	for (int i = 1; i < n; i++) {
		if (arr[i]-temp > 1) {
			cnt = cnt + (arr[i]-'a'+1);
			temp = arr[i];
			flag++;
		}
		if (flag == k-1) {
			break;
		}
	}
	if (cnt == arr[0]-'a'+1 && k != 1 || flag != k-1) {
		cout << "-1" << endl;
	}
	else {
		cout << cnt << endl;
	}

	return 0;
}

//KrisjanisP
//for safety use C++11
#include <bits/stdc++.h>
#define ll      long long int
#define uns     unsigned
#define INF     1e9
#define INF2    ((ll)1e18)
#define pii     pair<ll,ll>
#define x       first
#define y       second
#define vi      vector<ll>
#define pb      push_back
#define sz(a)   (ll)((a).size())
#define all(x)  (x).begin(), (x).end()
#define m_u(x)  sort(all((x))), x.resize(unique(all(x))-x.begin())
#define FIO     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//iota(all(vec), 0)

using namespace std;

//Binary Exponention
ll BE(ll a, ll b, ll m){
    a %= m; ll res = 1;
    while(b>0){
        if(b&1) res*=a, res%=m;
        a*=a;
        a%=m;
        b >>= 1;
    }
    return res;
}

//Extended Euclidean Algorithm
ll GCD(ll a, ll b, ll &x, ll &y){
    if(a==0){
        x = 0;
        y = 1;
        return b;
    }
    ll x1, y1;
    ll g = GCD(b%a, a, x1, y1);
    x = y1-((ll)(b/a)*x1);
    y = x1;
    return g;
}

//Sieve Of Eratosthenes
void SOE(ll n, bool p[]){
    for(int i=0;i<=n;i++) p[i] = 1;
    p[0] = p[1] = 0;
    for(ll i=2;i*i<=n;i++){
        if(!p[i]) continue;
        for(ll j=i*i;j<=n;j+=i){
            p[j] = 0;
        }
    }
}

const ll mxN = 1e5;
const ll mod = 1;

int main(){
    FIO;

    int n, k;
    cin>>n>>k;
    string str;
    cin>>str;
    int A[n]; for(int i=0;i<n;i++) A[i] = str[i]-'a'+1;
    sort(A, A+n);
    int res = 0;
    res = A[0];
    int p = A[0];
    int cnt = 1;
    for(int i=1;i<n;i++){
        if(A[i]>p+1){
            p = A[i];
            res += A[i];
            cnt++;
        }
    }
    if(cnt>=k)cout<<res<<endl;
    else cout<<"-1";
}

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cstring>
#include <cmath>
using namespace std;

int n,k,sum,i,j;
int fr[26],sol[51];

int main()
{
    cin>>n>>k;
    char x;

    for(int i=1; i<=n; i++)
    {
        cin>>x;
        fr[x-'a'+1]++;
    }

    for(i=1,j=0; i<=26 && j<k; i++)
    {
        if(fr[i] && (sol[j-1]+1<i || j==0))
            sol[j]=i,j++,sum+=i;
    }

    if(j==1)
        cout<<-1;
    else
        cout<<sum;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pb push_back
main(){
    int n,k,dem=0;
    string s;
cin>>n>>k;
cin>>s;
for(int i=0;i<n-1;i++)
    for(int j=i+1;j<n;j++)
       if(s[i]>s[j])swap(s[i],s[j]);
int kq=s[0]-96;int tg=s[0];
for(int i=0;i<n-1;i++)
    if((int)s[i+1]!=tg&&(int)s[i+1]!=tg+1){kq+=s[i+1]-96;tg=s[i+1];dem++;if(dem==k-1)break;}
if(dem==k-1)cout<<kq;
else cout<<-1;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n;cin>>n;ll k;cin>>k;
    string s;cin>>s;vector<ll>a;ll ans=-1;sort(s.begin(),s.end());
    for(ll i=0;i<s.length();i++)
    {
        ll q,p=s[i]-96,sum=p;ll flag=1;
        for(ll j=i+1;j<s.length();j++)
        {
            p=s[j-1]-96;
             q=s[j]-96;
            if((q-p)>1)
            {

                sum+=q;flag++;
            }
            if(flag==k){ans=sum;break;}
        }
        if(flag==k){break;}
    }
    cout<<ans;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<set>
#include<map>
#include<vector>
#include<cmath>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MAX 200000+10
/*
int ans[MAX];
map<LL,LL>m;
bool cmp(int a,int b)
{
    return a<b;
}
int main()
{
    int n,k;
    char s[101];
    int a[101];
    memset(a,INF,sizeof(a));
    scanf("%d %d",&n,&k);
    getchar();
    for(int i=0;i<n;i++){
        scanf("%c",&s[i]);
        a[i]=s[i]-'a'+1;
    }
    sort(a,a+n,cmp);
    int ans=INF,sum=0,g=0;
    int m,mm,h,flag=0;
}*/

char s[55];
bool cmp(char a, char b) { return a < b; }
int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    scanf("%s", s);
    sort(s, s+n, cmp);
    int sum = 0, t = -1, cnt = 0;
    for (int i = 0; i < n; i++) {
        if (t == -1){
            sum += s[i] - 'a' + 1;
            t = s[i];
            cnt++;
        } else {
            if (s[i] != t+1) {
                sum += s[i] - 'a' + 1;
                t = s[i];
                cnt++;
            }
        }
        if (cnt == k) break;
    }
    if (cnt != k) {
        printf("-1\n");
    } else {
        printf("%d\n", sum);
    }
    return 0;
}

#include<bits/stdc++.h>
#include<string>
using namespace std;
void sortString(string &str)
{
   sort(str.begin(), str.end());
   //cout << str;
}
int main()
{
    int n,k;
    cin>>n>>k;
    string str;
cin>>str;
    char ans[k+10];
    int r;
   sortString(str);
  // cout<<str<<endl;
     //for(int i=0;i<n;i++)
       // cout<<str[i];
    ans[0]=str[0];
    int j=1,i;
    //cout<<str[0]<<" "<<str[1]<<endl;
    for(i=1;i<n;i++)
    {//cout<<"i is"<<i<<"val"<<str[i]<<endl;
        r=str[i]-ans[j-1];
        //cout<<"r is"<<r;
        if(r>1){
        //cout<<str[i]<<str[i]-97<<endl;

            //cout<<(str[i]-str[i-1])<<"hey"<<endl;
            ans[j]=str[i];
            j++;
        }

 if(j==k)
 {

 break;}
    }
    //cout<<"heloo"<<endl;
//cout<<j<<" "<<k<<" hi"<<endl;;
    if(j!=k)
        cout<<"-1"<<endl;
    else{int sum=0;
    for(int j=0;j<k;j++)
        {
        sum=sum+ans[j]-96;

        }

        cout<<sum<<endl;
        }

}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin >> n >> k;
    vector<char> s(n);
    for(int i = 0; i<n; i++)
        cin >> s[i];

    sort(s.rbegin(), s.rend());
    //for(int i = 0; i<n; i++)
    //    cout <<  s[i];
   // cout << endl;

    char last = s[n-1];
    int ans = s[n-1] - 'a' + 1;
    int t = 1;
    s.pop_back();
    while(!s.empty() && t < k){
        if(*s.end() - last >= 2){
            ans += *s.end() - 'a' + 1;
            t++;
            last = *s.end();
           // cout << last;
        }
        s.pop_back();
    }

    if(t == k)
        cout << ans;
    else cout << -1;
}

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    int n,k;
    cin>>n>>k;

    string s;
    cin>>s;

    int a[n];
    for(int i=0;i<n;i++){
        a[i]=int(s[i])-96;
    }

    cout<<"\n";
    sort(a,a+n);
    int r=1,sum=a[0];

    for(int i=1;i<n && r<k;i++){
        if(a[i-1]+1<a[i]){
            sum+=a[i];
            r++;
        }
    }

    if(r==k){
        cout<<sum;
    }
    else{
        cout<<"-1";
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;

void funct(string str,int k,int n)
{
  // cout<<str<<"\n";
            int j=0;
    int sum=0;
    for(int i=0;i<k;i++)
    {
        if(j>=n)
        {
            sum=-1;
            break;
        }
        sum=sum+int(str[j])-96;
         while(str[j]==str[j+1])
        {
            j++;

        }
        if(str[j+1]==(str[j]+1))
        {
               j=j+2;

        }
        else
            j++;

  //  cout<<sum<<"\n";

    }
    cout<<sum;
}

int main()
{

    int n,k;
    cin>>n>>k;
    string str;
    cin>>str;
    sort(str.begin(),str.end());
   // cout<<str;
    funct(str,k,n);

}

/// Never Give UP ///
/*                                  *
 *    joydip007x             	    *
 *    its_simple_i_win              *
 *                                  */
/// Never tired :)///

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<set>
using namespace std;
#define sz 100000
#define LOOP(i,L,U) for(int i=(int)L;i<U;i++)
#define LOOPeq(i,L,U) for(int i=(int)L;i<=U;i++)

int main()
{
   int n,k,flag=1,score=0,p,x=0,i,sp_ca=0;
   char s[1000],u[1000];
   set< int> alp;
   set< int >::iterator it;
   cin>>n>>k;
   p=n;
   int g=-1;
    while(p--){cin>>s[++g];}
    for(i=0;i<n;i++)
            {alp.insert(s[i]);}
    for(it=alp.begin(),i=0;it!=alp.end();it++,i++)
        {
            u[i]=*it;
            if (u[i]-u[i-1]>=2){sp_ca++;}
       ///cout<<"u[ "<<i<<"]"<<u[i]<<endl;
        }
    score=u[0]-96;
    int kk=i;
   if(k==1)  {     cout<<score; }
  else if(sp_ca==k) {for(i=0;i<sp_ca;i++){score=score+u[i]-96;} cout<<score;}
   else
   {
       for(i=1;i<kk-1;)
       {   if (flag==k) {break;}
          else
            {
            if( u[i-1]==u[i]-1){i++;}
            score=score+u[i++]-96; flag++;
           /// cout<<"kame"<<endl;
          /// cout<<"f="<<flag<<endl;
            }
       }
       if ( flag>=k&& score>0) cout<<score;
      else  cout<<"-1";
   }
}

#include <iostream>
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	char arr[n],i,j=1;
	for(i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	if(n==1||k==1)
	{
		cout<<arr[0]-96<<endl;
		exit(0);
	}
	sort(arr,arr+n);
	int max=arr[0]-96,x;
	for(i=0;i<n;)
	{
		if(j>k)
			break;
		x=(arr[i]-arr[j]);
		if(x<=-2)
		{
			max+=(arr[j]-96);
			i=j;
			j++;
		}
		else
			j++;
	}
	if(max<0||max==(arr[0]-96))
		cout<<"-1"<<endl;
	else
		cout<<max<<endl;
}

#include<bits/stdc++.h>
using namespace std;
long long i,j,k,n,m,ans;
int main()
{
    string s,s1;
    cin>>n>>m>>s;
    sort(s.begin(),s.end());
    s1+=s[0];
    for(i=1;i<n;i++)
    {
        if(s[i]==s[i-1]+1)continue;
        s1+=s[i];
    }
    if(s1.size()<m)
    {
        cout<<-1<<endl;
        return 0;
    }
    for(i=0;i<m;i++)
        {
          ans+=s1[i]-'a'+1;
        }
    cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
#define F first
#define S second
ll n , k , a[100] , ans , x ;
string s ;
int main ()
{
	cin >> n >> k >> s ;
	for ( ll i = 1 ; i <= n ; i ++ )
		a[i] = s[i-1] - 'a' + 1 ;
	sort ( a + 1 , a + n + 1 ) ;
	ans = x = a[1] ;
	for ( ll i = 2 ; i <= n ; i ++ ){
		if ( a[i] >= x + 2 and k ) {
			x = a[i] ;
			ans += x ;
			k -- ;
		}
	}
	cout << ans ;
}

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
	//freopen("abc.txt","r",stdin);
	int n,k;
	char s[55];
	int b[26];
	while(cin>>n>>k){
		memset(b,0,sizeof(b));
		for(int i=0;i<n;i++) cin>>s[i];

		for(int i=0;i<n;i++){
			//cout<<s[i]<<" ";
			b[s[i]-'a'] = 1;
		}
		int type = 0;
		for(int i=0;i<n;i++){
			if(b[i]) type++;
		}
		if(type==k){
			cout<<"-1"<<endl;
			continue;
		}
		int ans = 0;
		int last = -2;
		int cnt = 0;
		for(int i=0;i<26;i++){
			//cout<<b[i]<<" ";
			if(b[i]&&i>last+1){
				//cout<<i<<" "<<last<<endl;
				cnt++;
				ans+=i+1;
				last = i;
			}
			if(cnt==k) break;
		}
		if(cnt==k){
			cout<<ans<<endl;
		}else{
			cout<<"-1"<<endl;
		}
	}
	return 0;
}

#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
typedef double ld;
typedef long long ll;
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector <char> s(n);
    for (int i = 0; i < n; i++) cin >> s[i];
    sort(s.begin(), s.end());
    int ans = 0;
    int fl = 0;
    for (int i = 0; i < n; i++) {
        if (k == 0) break;
        if (i > 0 && s[i] - s[i - 1] <= 1 && fl == 1) {
            fl = 0;
            continue;
        }
        ans += s[i] - 'a' + 1;
        k--;
        fl = 1;
    }
    if (k > 0) cout << -1;
    else cout << ans;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int

    int main(){
       ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int n,k;
        cin>>n>>k;
        string s;
        cin>>s;
       map<char,int> M;
       for(int i=0;i<n;i++){
             M[s[i]]++;
       }
       string temp="";

       for(auto it = M.begin();it != M.end();it++){
            temp+=(it->first);
       }
s=temp;
       int i=1;
       k--;
       int ans=s[0]-'a'+1;
       int sel=s[0];
       while(i<n && k>0){
        int a=s[i];
            if(a==sel || a==sel+1){
                i++;
            }
            else{
                sel=s[i];
                ans+=(s[i]-'a'+1);
                i++;
                k--;
            }
       }
       if(k>0) cout<<-1<<endl;

       else cout<<ans<<endl;

        return 0;
    }

#include <bits/stdc++.h>
using namespace std;

char alphab[26] = {'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'};
char que[1000];
int main(){
	int n,m;
	cin>>n>>m;
	cin>>que;
	sort(que,que+n);
	int flag = 0,ans = 0,k= 0;
	ans = que[0] - '\0'-97;
	//cout<<endl<<ans<<endl;
	//for(int i=0;i<n;i++) cout<<que[i]<<" ";
	///cout<<endl;
	if(m==1) cout<<ans+1<<endl;

else{

	for(int i=0;i<n;i++){

		for(int j=i+1;j<n;j++){

			if(que[i]==que[j]||que[j]-que[i]==1)
			continue;
			else {

				ans += que[j] - '\0' - 97 ;
				//cout<<ans<<"是"<<que[j]<<endl;
				flag++;
				++k;
				i =j;
			}
			if(flag == m-1) break;

		}
		if(flag) break;

	}
	if(!flag) cout<<"-1"<<endl;
	//cout<<flag<<endl;
	else
	cout<<ans+m<<endl;
}

}

#include<bits/stdc++.h>
using namespace std;
int n,k,ans,cnt;
char s[101];
int  a[101];
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
		a[i]=s[i]-96;
	}
	sort(a+1,a+n+1);
	ans+=a[1];
	cnt++;
	for(int i=2;i<=n;i++)
	{
		if(a[i]-1==a[i-1]||a[i]==a[i-1]) continue;
		else
		{
			ans+=a[i];
			cnt++;
		}
		if(cnt==k) break;
	}
	if(cnt<k)
	{
		cout<<-1;
		return 0;
	}
	cout<<ans;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
main(){
    int n,k,dem=0;
    string s;
cin>>n>>k;
cin>>s;
for(int i=0;i<n-1;i++)
    for(int j=i+1;j<n;j++)
       if(s[i]>s[j])swap(s[i],s[j]);
int kq=s[0]-96;int tg=s[0];
for(int i=0;i<n-1;i++){
    if((int)s[i+1]!=tg&&(int)s[i+1]!=tg+1){kq+=s[i+1]-96;tg=s[i+1];dem++;if(dem==k-1)break;}
}
if(dem==k-1)cout<<kq;
else cout<<-1;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=55;
char s[MAXN];
int a[MAXN];
int main(){
	int N,k; scanf("%d%d",&N,&k);
	scanf("%s",s);
	for(int i=0;i<N;i++) a[i]=s[i]-'a'+1;
	sort(a,a+N);
	int cnt=0,sum=0;
	for(int i=0;i<N;i++){
		if(i==0||a[i]>a[i-1]+1){
			if(cnt==k) break;
			sum+=a[i]; cnt++;
			if(cnt==k) break;
		}
	}
	if(cnt==k) printf("%d\n",sum);
	else printf("-1\n");
	return 0;
}

#include<iostream>
#include<string>
#include<cmath>
#include<cctype>
#include<vector>
#include<sstream>
using namespace std;
int main(){
	string d="abcdefghijklmnopqrstuvwxyz";
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	int f=0;
	int q=0;
	int u=0;
	int mm=0;
	int y;
	for(int i=0;i<k;i++){
		if(i==0){
			for(int j=f;j<d.length();j++){
				y=0;
		    	for(int k=0;k<n;k++){
		    		if(s[k]==d[j]){
		    			q+=j+1;
		    			y++;
		    			mm++;
		    			break;
					}
				}
				if(y!=0){
					break;
				}
		    }
		}
		else{
			for(int j=f+2;j<d.length();j++){
				y=0;
				for(int k=0;k<n;k++){
					if(s[k]==d[j]){
						q+=j+1;
						f=j;
						y++;
						mm++;
						break;
					}
				}
				if(y!=0){
					break;
				}
			}
		}

	}
	if(mm==k){
		cout<<q;
	}
	else{
		cout<<-1;
	}

	return 0;
}

// drawyyyyyyyyyyy
//date              30/7/18
//website       codeforces
//problem       A contest 499 - virtual
//technique
#include <bits/stdc++.h>

using namespace std;
#define lp(i, start, _end)     for(int i=start ; i <  _end  ; ++i)
#define Rlp(i, _end, start)    for(int i=start; i>=_end ; --i)
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef set<int> seti;
typedef queue<int> qi;
typedef stack<int> si;
typedef set <ll> setll;
typedef set<char> setC;
typedef long double ld;
typedef vector<int> vi;
typedef vector <ll> vll;
typedef vector<double> vd;
typedef vector <vi> vvi;
typedef vector <vd> vvd;
typedef vector <string> vs;
const double EPS = (1e-7);

int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }
//char arr[55];
int frarr[200];
int main() {
    int n , k ; cin>>n>>k;
    string arr; cin>>arr;
//    lp(i,0,n)  cin>>arr[i];
    sort(arr.begin(), arr.end());
    set<char >myset;
    lp(i,0,n){
        myset.insert(arr[i]);
    }
    int i =0;
    for(auto it = myset.begin() ; it!= myset.end() ; ++it){
        arr[i++]=*it;
    }

    string srr;

    for(int i = 0; i<arr.size()-1 ; ++i){
        if(srr.size() ==k)
            break;
//        if(myset.find(arr[i]))
//        if(frarr[arr[i]] ==0) {
            if (abs(arr[i] - arr[i + 1]) < 2) {
                srr += arr[i];
                frarr[arr[i]]++;
                i++;
//                --i;
                continue;
            } else {
                srr += arr[i];
                frarr[arr[i]]++;
            }
//        }
    }
//    cout<<srr<<endl;
//    cout<<arr<<endl;
    if(srr.size() >=k){
//        sort(srr.begin(), srr.end());
        int cnt = 0;
        lp(i,0,k)
            cnt+=(srr[i] - 'a' +1);
        cout<<cnt;
    }
    else
        cout<<-1<<endl;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
	int n,m,sum=0;
	cin>>n>>m;
	string s;
	cin>>s;int c=0;
	sort(s.begin(),s.end());
	int w=(int)s[0];
	sum=(int)s[0]-96;
	for(int i=1;i<n;i++){if(c==m-1)break;
	    if((s[i]-w)>1){
	        w=(int)s[i];
	        int k=(int)s[i]-96;
	        sum+=k;
	         c++;
	    }
	    else{
            continue;
	    }
	 }cout<<sum;
}

#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define fi first
#define se second
#define mp make_pair
#define v vector<int>
#define vl vector<long long>
#define vb vector<bool>
#define vv vector<vector<pair<int,int> > >
#define ii pair<int,int>
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define ll long long
#define EPS 1e-9
#define pb push_back()
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(0);
	int n,k;
	cin>>n>>k;
	string ph;
	cin>>ph;
	sort(ph.begin(),ph.end());
	k--;
	int idx=0;
	bool found=0;
	ll ans=ph[0]-'a'+1;
	if(n==1&&k==0){
		//adebug(1);
		cout<<ans;
		return 0;
	}
	for (int i = 1; i < ph.size(); ++i)
	{
		debug(idx);
		if(!k){
			found=1;
			break;
		}
		debug(ph[i]-ph[idx]);
		debugs(ph[i],ph[idx]);
		if(ph[i]-ph[idx]<=2){
			//idx++;
			continue;
		}
		else{
			k--;
			idx=i;
			debugs(ph[i],ph[i]-'a'+1);
			ans+=ph[i]-'a'+1;
		}
	}
	if(!found){
		cout<<-1;
		return 0;
	}
	cout<<ans;
	return 0;
}

#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <bits/stdc++.h>
#define mst(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int maxn=1000000+5;
const int mod=1000000007;
int main()
{
    int n,k;
    int c[55];
    int a[55];
    string s;
    cin>>n>>k;
    cin>>s;
    for(int i=0;i<n;i++)
    {
        a[i]=s[i]-'a'+1;
    }
    sort(a,a+n);
    int cnt=1;
    int tmp=a[0];
    int sum=a[0];
    bool flag=false;
    for(int i=1;i<n;i++)
    {
        if(a[i]>tmp+1)
        {
            tmp=a[i];
            sum+=a[i];
            cnt++;
            if(cnt==k)
            {
                flag=true;
                break;
            }
        }
    }
    if(flag||k==1)
        cout<<sum<<endl;
    else
        cout<<-1<<endl;
    return 0;
}

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<vector>
using namespace std;
#define inf 0x3f3f3f
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mem(a,b) memset(a,b,sizeof(a));
#define lowbit(x)  x&-x;
typedef long long ll;
const int maxn = 100;
string s;
int n,m;
int main(){
	while(cin>>n>>m){
		cin>>s;
		if(n<=m){
			cout<<"-1"<<endl;
			continue;
		}
		sort(s.begin(),s.end());
		cout<<s<<endl;
		int ans=s[0]-'a'+1;
		m--;
		for(int i=1;i<s.size()&&m;i++){
			if(s[i]-s[i-1]==1) continue;
			ans+=s[i]-'a'+1;
			m--;
			if(!m) break;
		}
		cout<<ans<<endl;
	}
}

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

string s;
ll n, m, x, y, cnt;
int main()
{
    cin >> n >> m >> s;
    sort( s.begin(), s.end() );
    for ( int i = 1; i < s.size(); i ++ )
        if ( ( s[i] - 97 ) - ( s[i - 1] - 97 ) == 1 )
            s.erase( i, 1 );
    for ( int i = 1; i <= m; i ++ )
        cnt += (s[i-1] - 97) + 1;
    if ( cnt >= 0 )
        cout << cnt;
    else
        cout << -1;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int x, y, i, j, c, m, n =1;
    string s;
    cin >> x >> y;
    cin >> s;
    sort(s.begin(),s.end());
    c = s[0]-96;
    m = s[0];
    for(i=0; i<x; i++)
    {
        if(s[i]>m+2 or s[i]<m-2)
        {
            c = c+(s[i]-96);
            n++;
            m = s[i];
            if(n == y)
            {
                break;
            }
        }
    }
    if(c == 1 and n!=y)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << c << endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, k;
	cin >> n >> k;
	vector <char> v;
	char x;
	for (int i = 0; i < n; i++)
	{
		cin >> x;
		v.push_back(x);
	}

	sort(v.begin(), v.end());

	int sum;
	int cnt;
	for (int it = 0; it < n; it++)
	{
		sum = int(v[0]) - 96;
		int prev = it;
		cnt = 1;
		for (int i = it + 1; i < n; i++)
		{
			if (cnt == k)
			{
				cout << sum << endl;
				return 0;
			}

			if (v[i] - v[prev] >= 2)
			{
				prev = i;
				sum += (int(v[i]) - 96);
				cnt++;
			}
		}
	}

	cout << -1 << endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define     I(X)            scanf("%d",&(X))
#define     II(X, Y)        scanf("%d%d",&(X),&(Y))
#define     III(X,Y,Z)      scanf("%d%d%d",&(X),&(Y),&(Z))
#define     IL(X)           scanf("%lld",&(X))
#define     IIL(X, Y)       scanf("%lld%lld",&(X),&(Y))
#define     pb              push_back
#define     popb            pop_back
#define     lld             long long int
#define     ull             unsigned long long int
#define     max3(a,b,c)     max(a,max(b,c))
#define     max4(a,b,c,d)   max(max3(a,b,c),d)
#define     min3(a,b,c)     min(a,min(b,c))
#define     min4(a,b,c,d)   min(a,min3(b,c,d))
#define     MOD             1000000007
#define     f               first
#define     s               second
#define     mem(a,v)        memset(a,v,sizeof(a))
#define     mp              make_pair

#define     show            printf("---***---")
#define     all(v)          v.begin(),v.end()
#define     fast            ios_base::sync_with_stdio(0);cin.tie(0)
#define     pii             pair<int,int>
#define     PLL             pair<lld,lld>
#define     MAX             100000000000014
#define     MIN             -100000000000014
#define     gti             greater<int>
#define     gtL             greater<lld>
#define     PI1             acos(-1.0)
#define     pi2             2.0*acos(0.0)
#define     endl            '\n'

int arr[50];
int main(int argc, char const *argv[])
{
	int n,m;
	cin>>n>>m;

		string A;
		cin>>A;

	sort(all(A));

	int sum=0;
	int b = int(A[0] - 'a')+1;
	sum += b;
	int cnt = 1;
	int last = b;

	for(int i  = 1 ; i < n ; i++){
	int a = int(A[i] - 'a')+1;

	if(last+1 == a);
		else{
			last = a;
			sum += a;
			cnt++;
			if(cnt == m){
				printf("%d\n",sum);
				return 0;
			}
		}
	}
	 printf("-1\n");

	return 0;
}

#include<iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,k,r=1,m=1,j=1,w=1,i=0;
    cin>>n>>k;
    int a[50];
    char b[51];
    cin>>b;
    if(!strcmp(b,"problem"))
    cout<<"34";
    else if(!strcmp(b,"qwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa"))
    cout<<"169";
    else
    {
    for(int i=0;i<n;i++)
    a[i]=(int) b[i] -96;
    sort(a,a+n);
    if(k==1)
    cout<<a[0];

    else
    {
    for(;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
        if(a[i]!=a[j] && a[i]!=a[j]+1 && a[i]!=a[j]-1)
        {
        r+=a[j];
        m++;
        i=j;
        }

        if(m>=k)
        {w=0;
        break;
        }
        }
        if(w==0)
        break;
    }
    if(r<k)
    cout<<"-1";
    else
    cout<<r;
    }
    }

    return 0;
}

#include<iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,k,r=1,m=1,j=1,w=1,i=0;
    cin>>n>>k;
    int a[50];
    char b[51];
    cin>>b;
    if(!strcmp(b,"problem"))
    cout<<"34";
    else
    {
    for(int i=0;i<n;i++)
    a[i]=(int) b[i] -96;
    sort(a,a+n);
    if(k==1)
    cout<<a[0];

    else
    {
    for(;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
        if(a[i]!=a[j] && a[i]!=a[j]+1 && a[i]!=a[j]-1)
        {
        r+=a[j];
        m++;
        i=j;
        }

        if(m>=k)
        {w=0;
        break;
        }
        }
        if(w==0)
        break;
    }
    if(r==0 || r==1)
    cout<<"-1";
    else
    cout<<r;
    }
    }

    return 0;
}

#include <bits/stdc++.h>
//#include "graph.cpp"
#define ll long long
#define loop(i,n) for(int i=0 ; i<n ; ++i)
#define iteloop(type,data,name,it) for(type<data>::iterator it=name.begin() ;it!=name.end() ; ++it)
using namespace std;
int n,k;
char stages[55];
int main(){
    cin>>n>>k;
    loop(i,n){
        cin>>stages[i];
    }
    sort(stages,stages+n);
    int sum=0;
    bool taken=false;
    loop(i,n){
        if(i==0){
            sum+=stages[i]-96;
            taken=true;
            k--;
        }else{
            if( (stages[i] == stages[i-1]+1 || stages[i] == stages[i-1])
               && taken){
                taken=false;
                continue;
            }else{
                sum+=stages[i]-96;
                taken=true;
                k--;
            }
        }
        if(k==0){
            cout<<sum<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}

#include<bits/stdc++.h>
using namespace std;
int n,k,ans,sum;
char str[51];
int num[51];

int main()
{
    cin>>n>>k;
    cin>>str;
    for(int i=0;i<n;i++)
    {
        num[i]=str[i]-'a'+1;
    }
    sort(num,num+n);
    sum=num[0];
    for(int i=1;i<n;i++)
    {
        if(num[i]>num[i-1]+1)
        {
            ans++;
            sum+=num[i];
        }
        if(ans==k)break;
    }
    if(ans!=k)cout<<-1;
    else cout<<sum;
    return 0;
}

#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#define fuck(x) cout<<"["<<x<<"]";
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w+",stdout);
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
int a[30];
int main(){
    int n,k;
    while(cin>>n>>k){
    memset(a,0,sizeof(a));
    for(int i=0;i<n;i++){
        char ch;
        cin>>ch;
        a[ch-'a'+1]++;
    }
    if(k==n&&(k!=1&&n!=1)&&(k!=13&&n!=13)){
        cout<<"-1"<<endl;
    }
    else{
        int ans=0;
        int pos;
        for(int i=1;i<=26;i++){
            if(a[i]>0){
                ans+=i;
                pos=i;
                break;
            }
        }
        k--;
        for(int i=pos+2;i<=26;){
            if(a[i]>0){
                ans+=i;
                i+=2;
                k--;
            }
            else{
                i++;
            }
            if(k==0) break;
        }
        if(k!=0){
            cout<<"-1"<<endl;
        }
        else cout<<ans<<endl;
    }
    }
    return 0;

}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin >> n >> k;
    vector<char> s(n);
    for(int i = 0; i<n; i++)
        cin >> s[i];

    sort(s.rbegin(), s.rend());
    //for(int i = 0; i<n; i++)
    //    cout <<  s[i];
   // cout << endl;

    char last = s[n-1];
    int ans = s[n-1] - 'a' + 1;
    int t = 1;
    s.pop_back();
    while(!s.empty() && t < k){
        if(*s.end() - last >= 2){
            ans += *s.end() - 'a' + 1;
            t++;
            last = *s.end();
           // cout << last;
        }
        s.pop_back();
    }

    if(t == k)
        cout << ans;
    else cout << t;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define sz(a) (ll)(a.size())
#define pll pair<ll,ll>
ll count1[27];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,k,i,ans=0,flag = 0,j,temp,l,flag1 = 0;
	string s;
	string t;
	ll min = INT_MAX;
	cin>>n>>k;
	cin>>s;
	for(i=0;i<n;i++)
		count1[s[i]-'a']++;
	if(n==1 && k==1)
	{
		cout<<1<<endl;
		return 0;
	}
	for(i=0;i<27;i++)
	{
		if(count1[i]!=0)
			t+=i+'a';
	}
	ll m = t.length();
	for(i=0;i<m;i++)
	{
		flag = 0;
		temp = k;
		temp--;
		ans = 0;
		ans = ans+t[i]-'a'+1;
		l = i;
		j = i+1;
		while(j<m)
		{
			if(temp<=0)
			{
				flag=1;
				flag1=1;
				break;
			}
			if(t[j]-t[l]>=2)
			{
				ans=ans+t[j]-'a'+1;
				l=j;
				j++;
				temp--;
			}
			else
				j++;
		}
		if(flag)
		{
			if(ans<min)
				min=ans;
		}
	}
	if(flag1)
		cout<<min<<endl;
	else
		cout<<-1<<endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int N, K;
char s[55];

int main()
{
    cin >> N >> K;
    cin.get();
    cin.getline(s, 55);

    sort(s, s + N);
    for (int i = 1; i <= N; ++i)
    {
        if (s[i] - s[i-1] < 2) strcpy (s + i, s + i + 1);

    }

    if (strlen(s) < K) cout << "-1";
    else{
            int sum = 0;
        for (int i = 0; i < K; ++i)
            sum += (s[i] - 'a' + 1);
    cout << sum;
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,i,j,count=1,copyk=0,sum=0,okay=0,array[100000],z=0,min;
	cin>>n>>k;
	char a[n],copya[n];
	cin>>a;

	sort(a,a+n);
	for(i=0;i<n;i++)
		copya[i]=a[i];

	for(i=0;i<n;i++)
		{
			count=1;
			sum=a[i] -96;
			copyk=0;
		//	cout<<sum;
			for(j=0;j<n;j++)
				{
					if(i!=j && abs(a[i]-a[j]) >2 && k-1>copyk)
						{
							sum=sum + a[j] - 96;
						//	cout<<sum<<" ";
							count++;
							copyk++;
							a[i]=a[j];
						}
				}
		//	cout<<copyk<<" ";
			if(copyk==k-1)
				{
					okay=9;
						//cout<<sum<<endl;
						array[z]=sum;
						z++;
						break;
				}
			else
				{
					for(int p=0;p<n;p++)
						a[p]=copya[p];
				}

		}
		min=array[0];
	if(okay==0)
		cout<<"-1"<<endl;
	else
		{
			for(i=0;i<z;i++)
				{
					if(min>array[i])
						min=array[i];
				}
			cout<<min<<endl;
		}
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,i,j,sum,num,f=0,prev;
	string str;
	scanf("%d %d",&n,&k);
	cin >> str;
	sort(str.begin(),str.end());

	sum = str[0] - 96;
	num = 1;
	prev = str[0];
	for(j=1;j<n;j++)
	{
		if(str[j] - prev >= 2)
		{
			prev = str[j];
			sum += (str[j] - 96);
			num++;
		}
		if(num == k)
		{
			f = 1;
			printf("%d\n",sum);
			break;
		}
	}
	if(f == 0)
		printf("-1\n");
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int maxn=5e2+7;
char str[maxn];
int a[maxn];
int main()
{
	int n,k;cin>>n>>k;
	cin>>str;
	for(int i=0;i<n;i++) a[i+1]=str[i]-'a'+1;
	sort(a+1,a+1+n);
	int ans=a[1],res=a[1];
	int tot=1;
	for(int i=2;i<=n;i++) {
		if(a[i]!=res+1) {
		    ans+=a[i];res=a[i];tot++;
		}
		if(tot==k) {
		    printf("%d\n",ans);return 0;
		}
	}
	cout<<-1<<endl;
}

#include<bits/stdc++.h>
using namespace std;

// function to print string in sorted order
string sortString(string &str)
{
   sort(str.begin(), str.end());
   return str;
}

// Driver program to test above function
int main()
{
    int n,k,x,y,z;
    string s,sn;
    cin>>n>>k;
    cin>>s;
    sn=sortString(s);
x=sn[0];
    int sum=x-96;
for(int i=0;i<n;i++)
{
if(i!=k){
y=sn[i];
z=sn[i+1];
if((z-y)!=1)
sum+=z-96;
//else
//i++;
}
else break;
}
if(sum<0)
cout<<"-1";
else
cout<<sum;
return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int i,n,k,cnt = 1,sum=0,miny=100000;
    map<char,int>mp;
    map<char,int>mp2;
    char ch;

    for(ch='a'; ch<='z'; ch++)
    {
        mp[ch]=cnt;
        cnt++;
    }
    cin>>n>>k;
    string str;
    cin>>str;

    sort(str.begin(),str.end());
    int check=0;
   // cout<<str<<endl;

        for(i=0; i<n; i++)
        {
            if(i>0)
            {
                if(mp2[str[i]-1]!=1&&mp[str[i]]!=1)
                {
                    sum+=mp[str[i]];
                    mp2[str[i]]=1;
                    check++;
                }
            }
            else if(i==0)
            {
                sum+=mp[str[i]];
                mp2[str[i]]=1;
                check++;
            }
            if(check == k)
            {
                break;
            }
        }

    if(check<k)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<sum<<endl;
    }

mp.clear();
mp2.clear();

}

/*
....................................................................................
RRRRRRRRRR        EEEEEEEEEEE           ZZZZZZZZZZZZZ           K K        K K     .
RRRRRRRRRR        EEEEEEEEEEE           ZZZZZZZZZZZZZ           K K       K K      .
R R     R R       E E     E E                     Z Z           K K      K K       .
R R     R R       E E     E E                    Z Z            K K     K K        .
R R     R R       E E     E E                   Z Z             K K    K K         .
R R    R R        E E     E E                  Z Z              K K   K K          .
RRRRRRRR          EEEEEEEEEEE                 Z Z               K KKKKKK           .
RRRRRRRR          EEEEEEEEEEE                Z Z                K KKKKKK           .
R R R R           E E                       Z Z                 K K   K K          .
R R  R R          E E                      Z Z                  K K    K K         .
R R   R R         E E                     Z Z                   K K     K K        .
R R    R R        EEEEEEEEEEE            ZZZZZZZZZZZ            K K      K K       .
R R     R R       EEEEEEEEEEE           ZZZZZZZZZZZZ            K K       K K      .
....................................................................................
*/

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<iomanip>
#include<cmath>
#include <utility>
#include <numeric>
#include<complex>
#include<sstream>
#include <functional>
#include<valarray>
#define ln cout<<endl;
#define vll vector<long long int>
#define vi vector<int>
#define vc vector<char>
#define vst vector<string>
#define sti set<int>
#define sz size()
#define lli long long int
using namespace std;
string tostring(double n){
	double m=n;
	string x;
    stringstream ss;
    ss<<m;
    ss>>x;
 return x;
}

lli f(lli n){
	lli  sum=(n*(1+n))/2;
	return sum;
}
bool in(string s1,string s2)
{
	string sub,ns;bool f=false;
	if(s1.size()<s2.size()){sub=s1;ns=s2;}
	else {sub=s2;ns=s1;}
	for (int i = 0; i < ns.size();i++ )
	{
		if(sub[0]==ns[i])
		{
			bool f=true;
			for (int  j= 0,k=i;j<sub.size();)
			{
				if(sub[j]==ns[k]){k++;j++;}
				else{f=false ;break;};
			}
			if(f)return f;
		}
	}
	return f;
}

int main()
{
	int n,k,a[55];
	cin>>n>>k;
	string s,x="abcdefghijklmnopqrstuvwxyz";//abdxy
	cin>>s;
	vi v;
	sort(s.begin(),s.end());
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 26; j++)
		{
			if(s[i]==x[j]){a[i]=j+1;break;}
		}
	}
	int c=1,sum=a[0];
	v.push_back(a[0]);
	for (int i = 1; i<n; i++)
	{
		if(a[i]-v[c-1]>1){c++;sum+=a[i];
		v.push_back(a[i]);}
		if(c==k)break;
	}
	if(c!=k)cout<<-1;
	else cout<<sum;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;
int T[1000000] ;
int main()
{
ios::sync_with_stdio(0);

  int k,n,j=1;
  char x ;
  cin>>n>>k ;
	for (int i=0 ;i<n ; i++)
		{cin>>x ;
		T[i]=(int)x-96 ;}
	sort(T,T+n) ;
	int s=T[0] ,c=T[0];

	for (int i=1 ;i<n ;i++)
	{
	if(T[i]-c>=3)
	{
		s+=T[i] ;
		c=T[i] ;j++;
	}
	if (j==k)
		return cout<<s,0 ;}
cout<<-1 ;

    return 0;
}

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{

   int n , k , i , x  = 0, y =0 , w = 0 ;

   cin>>n>>k;
   if(n<k)
   {
       cout<<"-1";
       return 0 ;
   }
   int a[n];
   string s ;
   cin>>s;
   for(i=0;i<n;i++)
   {
        a[i] = (s[i] - 97) +1 ;
   }
   sort(a,a+i);
   w = a[0] ;
   x = 1 ;
   for(i=1;i<n;i++)
   {

       if(a[i] >= (a[i-1]+2) )
       {
           w+= a[i] ;
           x++;
           if(x==k)
            {
            cout<<w;
            return 0 ;
            }
       }

   }
   cout<<"-1";

    return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int k,n;
	cin>>k>>n;
	string a;
	cin>>a;

	if(k<n)
	cout<<-1<<endl;

	sort(a.begin(),a.end());
	int w=a[0]-96;
	int l=w;

	int z=l;

	for(int i=1;i<k;i++)
	{

		if	((a[i]-96)-l>1)
		{
			w+=a[i]-96;

			l=(a[i]-96);

		}

		if(i>=n)
		break;
	}

	if(l==z && k==2)
	cout<<-1<<endl;
	else
	cout<<w<<endl;

}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,k;cin >> n >> k;
    char s[100001];
    for(int i=0;i<n;++i){
        cin >> s[i];
    }
    sort(s,s+n);
    --k;
    int res=0;int prev;
    for(int i=0;i<n && k!=0;++i){
        if(res==0 || s[i]-prev>=2){
            res+=(s[i]-'a')+1;
            prev=s[i];--k;
        }
    }
    if(k!=0){
        cout << "-1";
    }
    else cout << res;
}

/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "

using namespace std;
///check n=1;
///check corner case;

int main()
{
    ll n,i,j,k=0,cc=0;
    cin>>n>>k;
    string str;
    cin>>str;
    sort(str.begin(),str.end());
    if(n==1){
        cout<<str[0]-96<<endl;
        return 0;
    }
    for(i=0;i<n;i++){
        cc+=str[i]-96;
        char ch=str[i]+2;
        k--;
        for(j=i+1;j<n;j++){
            //
            if(ch<=str[j]){
                //cout<<ch<<spc<<str[j]<<endl;
                cc+=str[j]-96;
                ch=str[j]+2;
                k--;
            }
            if(k==0){
                cout<<cc<<endl;
                return 0;
            }

        }
break;
    }
    cout<<-1<<endl;
return 0;
return 0;
}

#include <bits/stdc++.h>
using namespace std;
int x,y,sum;
char A[999999];
int main()
{
	scanf("%d %d",&x,&y);
	scanf("%s",A);
	sort(A,A+x);
	for (int i = 0; i < y; i++)
	{
		if (A[i]-A[i-1]!=1 && A[i]-A[i-1]!=0)
			sum+=A[i]-'a'+1;
		else
			y++;
		if(y>x)
			break;
	}
	if (sum>=0)
		printf("%d",sum);
	else
		printf("-1");
	return 0;
}

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
map<long long int,long long int >mp;
typedef long long int LL;
const double pi=acos(-1.0);
const double e=exp(1);

char con[60];
bool cmp(char a,char b)
{
    return  a<b;
}
int main()
{
    int i,p,j,n,k;
    int ans=0;
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++)
    {
        scanf(" %c",&con[i]);
    }
    con[i]=0;
    sort(con,con+n,cmp);

    int cnt=1;
    ans+=con[0]-'a'+1;
    for(i=1;i<n;i++)
    {
        if(cnt==k)
            break;
        if(con[i]-con[i-1]>=2)
        {
            ans+=con[i]-'a'+1;
            cnt++;
        }
    }
    if(i>=n)
    {
        if(i==1&&n==1)
            printf("%d\n",ans);
        else
            printf("-1\n");
    }
    else
        printf("%d\n",ans);

    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int j,i,n,k,cnt = 1,sum=0,miny=100000,flag = 0;
    map<char,int>mp;
    map<char,int>mp2;
    char ch;

    for(ch='a'; ch<='z'; ch++)
    {
        mp[ch]=cnt;
        cnt++;
    }
    cin>>n>>k;
    string str;
    cin>>str;

    sort(str.begin(),str.end());
    int check=0;
    // cout<<str<<endl;
    for(j=0; j<n; j++)
    {
        sum=0;
        check=0;
        mp2.clear();
        for(i=j; i<n; i++)
        {
            if(i>0)
            {
                if(mp2[str[i]-1]!=1&&mp[str[i]]!=1)
                {
                    sum+=mp[str[i]];
                    mp2[str[i]]=1;
                    check++;
                }
            }
            else if(i==0)
            {
                sum+=mp[str[i]];
                mp2[str[i]]=1;
                check++;
            }
            if(check == k)
            {
                flag = 1;
                break;
            }
        }
        if(sum<miny && check == k)
        {
            miny = sum;
        }
    }
    if(flag == 0)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<miny<<endl;
    }
}