#include <bits/stdc++.h>
using namespace std;
int ans = 0;
int k;
vector<int> Q;
vector<char> T;
int n;
set<vector<pair<int, char> > > used[105];
int suff[105];
set<vector<pair<int, char> > > tmp;
vector<pair<int, char> > go;
void dfs(int s, int len, int add) {
  if (suff[s] < len) return;
  if (used[s].find(go) != used[s].end()) return;
  used[s].insert(go);
  if (s == (int)Q.size() || len == 0) {
    if (tmp.find(go) == tmp.end()) {
      tmp.insert(go);
      ans += add;
      if (k == (int)tmp.size()) {
        cout << ans;
        exit(0);
      }
    }
    return;
  }
  for (int cnt = 0; cnt <= min(len, Q[s]); ++cnt) {
    if ((int)go.size() == 0 || go.back().second != T[s]) {
      if (cnt != 0) {
        go.push_back({cnt, T[s]});
        dfs(s + 1, len - cnt, add);
        go.pop_back();
      } else
        dfs(s + 1, len - cnt, add);
    } else {
      go.back().first += cnt;
      dfs(s + 1, len - cnt, add);
      go.back().first -= cnt;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  if (k <= 1) {
    cout << 0;
    return 0;
  }
  k--;
  string s;
  cin >> s;
  int len = 1;
  char gg = s[0];
  for (int i = 1; i < n; ++i) {
    if (s[i] == s[i - 1])
      len++;
    else {
      Q.push_back(len);
      len = 1;
      T.push_back(gg);
      gg = s[i];
    }
  }
  Q.push_back(len);
  T.push_back(gg);
  for (int i = (int)Q.size() - 1; i >= 0; --i) suff[i] = suff[i + 1] + Q[i];
  for (int i = n - 1; i >= 1; --i) {
    for (int j = 0; j <= n; ++j) used[j] = {};
    dfs(0, i, n - i);
  }
  if ((int)tmp.size() + 1 == k) {
    ans += n;
    cout << ans;
    return 0;
  }
  cout << -1;
  return 0;
}
