#include <bits/stdc++.h>
using namespace std;
int n, k;
unordered_set<string> s;
queue<string> q;
bool can = false;
int main(void) {
  scanf("%d %d", &n, &k);
  string in;
  cin >> in;
  s.insert(in);
  q.push(in);
  if (s.size() == k) can = true;
  while (!can && !q.empty()) {
    string cur = q.front();
    q.pop();
    for (int i = 0; i < cur.size(); ++i) {
      string nw = cur.substr(0, i) + cur.substr(i + 1);
      if (!s.count(nw)) {
        s.insert(nw);
        q.push(nw);
        if (s.size() == k) can = true;
      }
      if (can) break;
    }
  }
  if (can) {
    int sum = 0;
    for (auto i : s) sum += n - i.size();
    printf("%d\n", sum);
  } else
    puts("-1");
}
