#include <bits/stdc++.h>
namespace DECLARATIONS {
using namespace std;
using ll = long long;
using PI = pair<int, int>;
template <class T>
using V = vector<T>;
using VI = V<int>;
template <class T>
inline void debug(T &A) {}
template <class T>
inline void debug_dim2(T &A) {}
template <typename... Args>
inline void debug(const char *format, Args const &...args) {}
template <typename... Args>
string format(const std::string &fmt, Args... args) {
  size_t len = std::snprintf(nullptr, 0, fmt.c_str(), args...);
  std::vector<char> buf(len + 1);
  std::snprintf(&buf[0], len + 1, fmt.c_str(), args...);
  return std::string(&buf[0], &buf[0] + len);
}
}  // namespace DECLARATIONS
using namespace DECLARATIONS;
const int MOD = 1000000007;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  V<VI> dp(N + 1, VI(N + 1));
  dp[0][0] = 1;
  VI last(26);
  for (int i = 0; i < N; ++i) {
    int c = S[i] - 'a';
    for (int j = last[c]; j <= i; ++j) {
      for (int k = 1; k < N + 1; ++k) {
        dp[i + 1][k] += dp[j][k - 1];
        dp[i + 1][k] = min(dp[i + 1][k], K);
      }
    }
    debug(dp[i + 1]);
    last[c] = i + 1;
  }
  int total = 0;
  int ans = 0;
  for (int j = N; j >= 0; --j) {
    int acc = 0;
    for (int i = 0; i <= N; ++i) {
      acc += dp[i][j];
      acc = min(acc, K);
    }
    int cnt = min(K - total, acc);
    total += cnt;
    ans += (N - j) * cnt;
  }
  cout << (total == K ? ans : -1);
  return 0;
}
