#include <bits/stdc++.h>
using namespace std;
void printQ(queue<string> q) {
  while (!q.empty()) {
    cout << q.front() << " ";
    q.pop();
  }
  cout << "\n";
}
int main() {
  int n, k;
  string str;
  cin >> n >> k >> str;
  queue<string> queue;
  unordered_set<string> vis;
  int cost = 0;
  queue.push(str);
  vis.insert(str);
  while (!queue.empty()) {
    string curr = queue.front();
    queue.pop();
    k--;
    cost += str.length() - curr.length();
    if (k == 0) {
      cout << cost << endl;
      return 0;
    }
    for (int i = 0; i < curr.length(); i++) {
      string tmp = curr;
      tmp.erase(i, 1);
      if (!vis.count(tmp)) {
        vis.insert(tmp);
        queue.push(tmp);
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
