#include <bits/stdc++.h>
using namespace std;
int n, k;
string s;
map<string, bool> V;
int countt = 0, ans = 0;
void bfs() {
  queue<string> q;
  q.push(s);
  countt++;
  while (!q.empty() && countt <= k) {
    string M = q.front();
    q.pop();
    for (int j = 0; j < M.size(); j++) {
      string temp = M.substr(0, j);
      temp = temp + M.substr(j + 1, M.size() - 1);
      if (!V[temp]) {
        q.push(temp);
        countt++;
        V[temp] = 1;
        if (countt <= k) {
          ans += n - M.size() + 1;
        }
      }
    }
  }
}
signed main() {
  cin >> n >> k;
  cin >> s;
  bfs();
  if (countt < k) {
    cout << "-1";
    return 0;
  }
  cout << ans;
}
