#include <bits/stdc++.h>
using namespace std;
const long long INFLL = (long long)1e16;
const int INF = (int)1e8;
int bfs(string s, int k) {
  int n = (int)s.size();
  queue<string> q;
  set<string> visited;
  q.emplace(s);
  visited.emplace(s);
  long long res = 0;
  while (!q.empty() && (int)visited.size() < k) {
    string nex = q.front();
    q.pop();
    for (int i = 0; i < (int)nex.size(); i++) {
      string nei = nex;
      nei.erase(i, 1);
      if (!visited.count(nei) && (int)visited.size() + 1 <= k) {
        q.emplace(nei);
        visited.emplace(nei);
        res += n - (int)nei.size();
      }
    }
  }
  return ((int)visited.size() < k) ? -1 : res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int k;
  cin >> k;
  string s;
  cin >> s;
  set<string> used;
  cout << bfs(s, k) << endl;
  return 0;
}
