#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const array<long long int, 2> &a,
               const array<long long int, 2> &b) {
  return (a[0] > b[0]);
}
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
bool inline isPrime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
bool isPowerOfTwo(long long int n) {
  if (n == 0) return false;
  return (ceil(log2(n)) == floor(log2(n)));
}
bool prtv(vector<long long int> e) {
  for (auto &i : e) cout << i << " ";
  cout << "\n";
}
void prt(int i) {
  if (i == 1)
    cout << "YES\n";
  else
    cout << "NO\n";
}
int getSum(int n) {
  int sum = 0;
  while (n != 0) {
    sum = sum + n % 10;
    n = n / 10;
  }
  return sum;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int test = 1;
  while (test--) {
    set<string> hai;
    queue<string> bachi;
    long long int count = 0, k, ans = 0, n;
    cin >> n >> k;
    string s;
    cin >> s;
    bachi.push(s);
    while (!bachi.empty() && count < k) {
      string temp = bachi.front();
      bachi.pop();
      long long int sz = temp.size();
      if (hai.find(temp) != hai.end()) continue;
      hai.insert(temp);
      count++;
      ans += (n - sz);
      if (sz == 1) continue;
      string foo;
      for (long long int i = (0); i < (sz); i += 1) {
        foo = temp;
        foo = foo.erase(i, 1);
        bachi.push(foo);
      }
    }
    if (count == k - 1) ans += n;
    if (count < k - 1) ans = -1;
    cout << ans << "\n";
  }
}
