#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, ans = 0;
  string s;
  cin >> n >> k >> s;
  set<string> x;
  queue<string> q;
  q.push(s);
  int val = -1;
  while (q.size() > 0 && x.size() < k) {
    int t = q.size();
    val += 1;
    while (t-- && x.size() < k) {
      string now = q.front();
      q.pop();
      if (x.count(now)) {
        continue;
      }
      ans += val;
      x.insert(now);
      for (int j = 0; j < now.size(); j += 1) {
        string f = now;
        f.erase(f.begin() + j);
        if (!x.count(f)) {
          q.push(f);
        }
      }
    }
  }
  if (x.size() < k) {
    cout << -1;
  } else {
    cout << ans;
  }
}
