#include <bits/stdc++.h>
using namespace std;
map<string, bool> mark;
queue<string> Q;
int n, k, ans;
string s;
int main() {
  cin >> n >> k >> s;
  Q.push(s);
  mark[s] = true;
  while (Q.size()) {
    string t, tmp = Q.front();
    Q.pop();
    k--;
    ans += n - tmp.size();
    if (k == 0) break;
    for (int i = 0; i < tmp.size(); ++i) {
      t = tmp;
      t.erase(i, 1);
      if (!mark[t]) Q.push(t);
      mark[t] = true;
    }
  }
  if (k)
    cout << "-1";
  else
    cout << ans;
  return 0;
}
