#include <bits/stdc++.h>
using namespace std;
void Run() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
}
const int N = 2e5 + 20;
int a[N];
int solve(int n) {
  int sum = 0;
  while (n != 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main() {
  Run();
  int n, k;
  cin >> n >> k;
  queue<string> s;
  map<string, bool> vis;
  string x;
  cin >> x;
  s.push(x);
  k--;
  if (k == 0) {
    cout << 0 << "\n";
    return 0;
  }
  long long cost = 0;
  while (!s.empty()) {
    string cur = s.front();
    s.pop();
    for (int i = 0; i < cur.size(); i++) {
      string nxt = cur;
      nxt.erase(i, 1);
      if (vis.find(nxt) == vis.end()) {
        cost += n - nxt.size();
        vis[nxt] = 1;
        if (vis.size() >= k) {
          cout << cost << "\n";
          return 0;
        }
        s.push(nxt);
      }
    }
  }
  cout << -1 << "\n";
}
