#include <bits/stdc++.h>
using namespace std;
const long long int huge = 1e17;
long long int max(long long int a, long long int b) {
  if (a > b) return a;
  return b;
}
long long int min(long long int a, long long int b) {
  if (a < b) return a;
  return b;
}
long long int abbs(long long int a, long long int b) {
  if (a - b < 0) return b - a;
  return a - b;
}
long long int lowerB(vector<long long int> &v, long long int val) {
  long long int ind = v.size(), l = 0, r = v.size(), mid;
  while (l <= r) {
    mid = (l + r) / 2;
    if (v[mid] >= val) {
      ind = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  return ind;
}
void solve() {
  long long int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  queue<string> q;
  set<string> second;
  q.push(s);
  second.insert(s);
  long long int ans = 0;
  while (!q.empty()) {
    string v = q.front();
    q.pop();
    ans += n - v.length();
    k--;
    if (k == 0) break;
    for (long long int i = 0; i < v.length(); i++) {
      string temp = v;
      temp.erase(temp.begin() + i);
      if (!second.count(temp)) {
        q.push(temp);
        second.insert(temp);
      }
    }
  }
  if (k > 0) {
    cout << "-1\n";
  } else
    cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  t = 1;
  while (t--) {
    solve();
  }
}
