#include <bits/stdc++.h>
using namespace std;
long long n, k, kol = 1, ans = 0;
string s, tmp;
set<string> myset;
queue<string> q;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  cin >> s;
  if (k == 1) {
    cout << 0;
    return 0;
  }
  q.push(s);
  myset.insert(s);
  while (!q.empty()) {
    string top = q.front();
    q.pop();
    for (int i = 0; i < top.size(); i++) {
      tmp = top;
      tmp.erase(i, 1);
      if ((myset.find(tmp) == myset.end())) {
        kol++;
        myset.insert(tmp);
        q.push(tmp);
        ans += ((long long)s.size() - (long long)tmp.size());
        if (kol == k) {
          cout << ans;
          return 0;
        }
      }
    }
  }
  cout << -1;
  return 0;
}
