#include <bits/stdc++.h>
using namespace std;
int n, k;
long long res;
string s;
unordered_map<string, bool> d[103];
void bfs() {
  if (k == 0) return;
  queue<string> Q;
  d[s.size()][s] = 1;
  Q.push(s);
  while (!Q.empty()) {
    string S = Q.front(), S1;
    Q.pop();
    if (S == "") return;
    if (d[S.size()].size() != 0) d[S.size()].clear();
    S1.resize(S.size() - 1);
    for (int i = 1; i < S.size(); i++) {
      S1[i - 1] = S[i];
    }
    if (d[S1.size()][S1] == 0) {
      d[S1.size()][S1] = 1;
      res += n - S1.size();
      k--;
      if (k == 0) return;
      Q.push(S1);
    }
    for (int i = 0; i < S1.size(); i++) {
      S1[i] = S[i];
      if (d[S1.size()][S1] == 0) {
        d[S1.size()][S1] = 1;
        res += n - S1.size();
        k--;
        if (k == 0) return;
        Q.push(S1);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k >> s;
  k--;
  bfs();
  if (k == 0)
    cout << res;
  else
    cout << -1;
  return 0;
}
