#include <bits/stdc++.h>
using namespace std;
function<void(void)> ____ = []() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
};
const int MAXN = 111;
char s[MAXN];
int_fast64_t n, k, f[MAXN][MAXN], tot[MAXN];
int main() {
  ____();
  cin >> n >> k >> (s + 1);
  f[0][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = i - 1; j >= 0; j--) {
      for (int p = 0; p <= j; p++) f[i][p + 1] += f[j][p];
      if (s[j] == s[i]) break;
    }
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= i; j++) tot[j] += f[i][j];
  int_fast64_t cost = 0;
  for (int i = n; i >= 0 && k; i--) {
    int_fast64_t nd = min(k, tot[i]);
    cost += (n - i) * nd;
    k -= nd;
  }
  if (k == 0)
    cout << cost << endl;
  else
    cout << -1 << endl;
  return 0;
}
