#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long po(long long x, long long n) {
  long long ans = 1;
  while (n > 0) {
    if (n & 1) ans = (ans * x);
    x = (x * x);
    n /= 2;
  }
  return ans;
}
void func() {
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  string t = "!";
  s = t.append(s);
  long long dp[n + 1][n + 1];
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++) dp[i][j] = 0;
  long long f[26] = {0};
  for (int i = 1; i <= n; i++) {
    if (f[s[i] - 'a'] == 0) {
      dp[1][i] = 1;
      f[s[i] - 'a'] = 1;
    }
  }
  for (int i = 2; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      for (int k = j - 1; k >= 1; k--) {
        dp[i][j] += dp[i - 1][k];
        if (s[j] == s[k]) break;
      }
    }
  }
  long long ans = 0;
  long long cnt = 0;
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= n; j++) {
      if (cnt + dp[i][j] <= k) {
        cnt += dp[i][j];
        ans += (n - i) * dp[i][j];
      } else {
        ans += (n - i) * (k - cnt);
        cnt = k;
      }
      if (cnt == k) {
        cout << ans << "\n";
        return;
      }
    }
  }
  if (k - cnt == 1)
    cout << ans + n << "\n";
  else
    cout << -1 << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) func();
}
