#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  long long k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<int> last(26, -1);
  vector<vector<long long>> dp(n + 1, vector<long long>(n + 1));
  dp[0][0] = 1;
  const long long INF = 1e18;
  for (int i = 0; i < n; i++) {
    dp[i + 1][0] = 1;
    for (int j = 1; j <= n; j++) {
      long long minus = 0;
      if (last[s[i] - 'a'] != -1) minus = dp[last[s[i] - 'a']][j - 1];
      dp[i + 1][j] = min(INF, dp[i][j - 1] - minus + dp[i][j]);
    }
    last[s[i] - 'a'] = i;
  }
  long long ans = 0;
  for (int i = n; i >= 0; i--) {
    long long x = min<long long>(k, dp[n][i]);
    ans += (n - i) * x;
    k -= x;
  }
  if (k > 0) ans = -1;
  cout << ans << '\n';
  return 0;
}
