#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  queue<string> q;
  set<string> u;
  q.push(s);
  u.insert(s);
  int sum = 0;
  int siz = 1;
  while (!q.empty() && u.size() < k) {
    string v = q.front();
    q.pop();
    for (int i = 0; i < v.length(); i++) {
      string e = v;
      e.erase(i, 1);
      if (!u.count(e) && u.size() + 1 <= k) {
        u.insert(e);
        q.push(e);
        sum += s.length() - e.length();
      }
    }
  }
  if (u.size() < k)
    cout << -1;
  else {
    cout << sum;
  }
}
