#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  queue<string> q;
  q.push(s);
  set<string> ans_set;
  ans_set.insert(s);
  while (!q.empty()) {
    string v = q.front();
    q.pop();
    if ((int)ans_set.size() == k) break;
    for (int i = 0; i < (int)v.size(); ++i) {
      string u = "";
      for (int j = 0; j < (int)v.size(); ++j) {
        if (i == j) continue;
        u += v[j];
      }
      if (ans_set.count(u) == 0) {
        ans_set.emplace(u);
        q.push(u);
      }
      if ((int)ans_set.size() == k) break;
    }
  }
  assert((int)ans_set.size() <= k);
  if ((int)ans_set.size() == k) {
    int ans = 0;
    for (string el : ans_set) {
      ans += n - (int)el.size();
    }
    cout << ans << endl;
  } else {
    cout << "-1\n";
  }
}
