#include <bits/stdc++.h>
using namespace std;
long long solve(const string &s, const int n, int k) {
  if (k == 1) return 0;
  set<string> used;
  queue<string> q;
  long long cost = 0;
  used.insert(s);
  q.push(s);
  while (!q.empty() && (int)used.size() < k) {
    auto v = q.front();
    q.pop();
    for (int(i) = 0; (i) < ((int)v.size()); ++(i)) {
      auto nv = v;
      nv.erase(i, 1);
      if (!used.count(nv)) {
        q.push(nv);
        used.insert(nv);
        cost += n - (int)nv.size();
        if ((int)used.size() == k) return cost;
      }
    }
  }
  return -1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q = 1;
  while (q--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    cout << solve(s, n, k) << endl;
  }
  return 0;
}
