#include <bits/stdc++.h>
using namespace std;
using namespace std;
bool comp(int a, int b) { return (a < b); }
long long int nCr(long long int n, long long int r) {
  long long int temp1 = 1, temp2 = 1;
  for (long long int i = r + 1; i <= n; ++i) {
    temp1 *= i;
  }
  for (long long int i = 1; i <= n - r; ++i) {
    temp2 *= i;
  }
  return (temp1 / temp2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  queue<string> q;
  set<string> word;
  q.push(s);
  word.insert(s);
  long long int ans = 0;
  while (word.size() < k && q.empty() == false) {
    string popped = q.front();
    q.pop();
    for (long long int i = 0; i <= popped.length() - 1; ++i) {
      string obtined = popped;
      obtined = obtined.erase(i, 1);
      if (word.count(obtined) == 0 && word.size() < k && obtined.length() > 0) {
        word.insert(obtined);
        q.push(obtined);
        ans += (s.length() - obtined.length());
      }
    }
  }
  if (word.size() == k - 1) {
    word.insert("");
    ans += s.length();
  }
  if (word.size() == k)
    cout << ans << endl;
  else
    cout << "-1" << endl;
  return 0;
}
