#include <bits/stdc++.h>
using namespace std;
int n, k;
string s;
map<string, bool> vs;
int tmp;
int res;
void BFS() {
  queue<string> q;
  q.push(s);
  vs[s] = true;
  while (!q.empty()) {
    string t = q.front();
    q.pop();
    tmp++;
    res += (n - t.length());
    if (tmp == k) return;
    for (int i = 0; i < t.size(); i++) {
      string ts = "";
      for (int j = 0; j < t.size(); j++)
        if (j != i) ts += t[j];
      if (vs[ts]) continue;
      q.push(ts);
      vs[ts] = true;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  cin >> s;
  res = 0;
  tmp = 0;
  BFS();
  if (tmp < k)
    cout << -1;
  else
    cout << res << endl;
  return 0;
}
