#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int solve() {
  long long int n, k, l;
  cin >> n >> k;
  string s;
  cin >> s;
  l = s.size();
  int cost = 0;
  queue<string> q;
  q.push(s);
  mp[s] = 1;
  while (!q.empty()) {
    string top = q.front();
    q.pop();
    cost += l - (int)top.size();
    k--;
    if (k == 0) {
      break;
    }
    for (int i = 0; i < (int)top.size(); i++) {
      string temp = top;
      temp.erase(i, 1);
      if (mp[temp] == 0) {
        q.push(temp);
        mp[temp] = 1;
      }
    }
  }
  if (k >= 1) {
    cost = -1;
  }
  cout << cost;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  t = 1;
  while (t--) {
    solve();
  }
}
