#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
long long dp[111][28], sum[111];
char s[111];
int main() {
  int n;
  long long k;
  scanf("%d%I64d", &n, &k);
  scanf("%s", s);
  sum[0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j; j--) {
      if (sum[j] != inf)
        sum[j] = min(inf, sum[j] - dp[j][s[i] - 'a'] + sum[j - 1]);
      dp[j][s[i] - 'a'] = min(inf, sum[j - 1]);
    }
  }
  long long res = 0;
  for (int i = n; i >= 0; i--) {
    long long x = min(k, sum[i]);
    res += (n - i) * x;
    k -= x;
  }
  if (k)
    printf("-1\n");
  else
    printf("%I64d\n", res);
}
