func_code_string: #include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const int dir[8][2] = {{0, 1}, {1, 0},  {0, -1},  {-1, 0},                          {1, 1}, {1, -1}, {-1, -1}, {-1, 1}};   const int mod = 1e9 + 7, gakki = 5 + 2 + 1 + 19880611 + 1e9;   const int MAXN = 1e6 + 5, MAXM = 1e6 + 5;   const int MAXQ = 100010, INF = 1e9;   inline void read(int &v) {     v = 0;     char c = 0;     int p = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) {         p = -1;       }       c = getchar();     }     while (c >=  0  && c <=  9 ) {       v = (v << 3) + (v << 1) + c -  0 ;       c = getchar();     }     v *= p;   }   int n, m;   int len;   int anser = INT_MAX;   int num[55];   void dfs(int x, int where, int sum) {     for (int i = x + 1; i <= len; i++) {       if (num[i] >= num[x] + 2) {         if (where == m - 1) {           anser = min(anser, sum + num[i]);           return;         }         dfs(i, where + 1, sum + num[i]);         break;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     string ch;     cin >> ch;     len = ch.size();     for (int i = 0; i < len; i++) {       num[i + 1] = (ch[i] -  a ) + 1;     }     sort(num + 1, num + 1 + len);     num[len + 1] = INT_MAX;     if (m == 1) {       cout << num[1] << endl;       return 0;     }     for (int i = 1; i <= len - m + 1; i++) {       dfs(i, 1, num[i]);     }     if (anser == INT_MAX) {       cout << -1 << endl;     } else {       cout << anser << endl;     }     return 0;   }   