#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const double INF = 1e8;
const int maxn = 1e5 + 10;
const long long mod = 1e9 + 7;
int n, k;
string s;
int main() {
  cin >> n >> k >> s;
  set<string> ss;
  queue<string> q;
  int cnt = 0;
  int cost = 0;
  q.push(s);
  ss.insert(s);
  while (!q.empty()) {
    string cur = q.front();
    q.pop();
    cost += n - cur.length();
    if (++cnt == k) break;
    for (int t = (0); t < (cur.length()); ++t) {
      string nx = cur;
      nx.erase(t, 1);
      if (!ss.count(nx)) {
        ss.insert(nx);
        q.push(nx);
      }
    }
  }
  if (ss.size() < k)
    cout << -1;
  else
    cout << cost;
}
