#include <bits/stdc++.h>
using namespace std;
string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
const long double pie = 3.1415926535897932384626;
const long long mod = 1e9 + 7;
void solve(int test_case) {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  queue<string> q;
  q.push(s);
  set<string> vis;
  vis.insert(s);
  while (q.empty() == false) {
    auto node = q.front();
    q.pop();
    int z = node.size();
    if ((int)vis.size() == k) break;
    for (int i = 0; i < z; i++) {
      string to = node.substr(0, (i)) + node.substr(i + 1, n - i - 1);
      if (vis.count(to) == 0) {
        q.push(to);
        vis.insert(to);
        int z_vis = vis.size();
        if (z_vis == k) break;
      }
    }
  }
  if ((int)vis.size() != k) {
    cout << -1;
    cout << "\n";
    ;
    return;
  }
  int ans = 0;
  for (auto i : vis) {
    int z = i.size();
    int del = n - z;
    ans += del;
  }
  cout << ans;
  cout << "\n";
  ;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  for (int i = 0; i < t; i++) solve(i);
  return 0;
}
