#include <bits/stdc++.h>
using namespace std;
vector<pair<char, long long> > chars;
string s2;
set<string> used;
void solve(long long index, long long del) {
  long long count = chars[index].second;
  char c = chars[index].first;
  if (index == chars.size()) {
    if (del == 0) used.insert(s2);
    return;
  }
  for (long long i = max(0ll, count - del); i <= count; i++) {
    for (long long j = 0; j < i; j++) s2.push_back(c);
    solve(index + 1, del - count + i);
    for (long long j = 0; j < i; j++) s2.pop_back();
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  long long n, k;
  string s;
  cin >> n >> k >> s;
  long long r = 0;
  chars.push_back({s[0], 1});
  for (long long i = 1; i < n; i++) {
    if (s[i] == chars.back().first)
      chars[chars.size() - 1].second++;
    else
      chars.push_back({s[i], 1});
  }
  for (long long i = 0; (i <= n && k > 0); i++) {
    used.clear();
    solve(0, i);
    r += i * min(k, (long long)used.size());
    k -= used.size();
  }
  k > 0 ? cout << "-1\n" : cout << r << "\n";
}
