#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  queue<string> q;
  set<string> ans;
  q.push(s);
  ans.insert(s);
  while (!q.empty() and ans.size() < k) {
    string now = q.front();
    q.pop();
    for (long long i = 0; i < now.size(); i++) {
      string again = now;
      again.erase(i, 1);
      if (!ans.count(again) and ans.size() < k) {
        q.push(again);
        ans.insert(again);
      }
    }
  }
  if (ans.size() < k) {
    cout << -1 << "\n";
    return 0;
  }
  long long res = 0;
  for (auto &v : ans) {
    res += (n - v.size());
  }
  cout << res << "\n";
}
