#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  long long dp[n][n + 1];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= n; j++) {
      dp[i][j] = 0;
    }
  }
  dp[0][1] = 1;
  for (int i = 2; i <= n; i++) {
    dp[0][i] = 0;
  }
  for (int i = 1; i < n; i++) {
    bool baggage = false;
    dp[i][1] = 1;
    for (int j = i - 1; j >= 0 && !baggage; j--) {
      for (int k = 2; k <= (j + 2); k++) {
        dp[i][k] += dp[j][k - 1];
        if (s[i] == s[j]) {
          baggage = true;
          dp[i][1] = 0;
        }
      }
    }
  }
  dp[0][0] = 1;
  long long ans = 0;
  for (int i = n; i >= 0 && k > 0; i--) {
    for (int j = n - 1; j >= 0 && k > 0; j--) {
      int totake = min(dp[j][i], k);
      k -= totake;
      ans += totake * (n - i);
      dp[j][i] -= totake;
    }
  }
  if (k > 0) {
    cout << -1 << endl;
  } else
    cout << ans << endl;
  return 0;
}
