#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) {
  if (x == 0) return y;
  return gcd(y % x, x);
}
long long powmod(long long x, long long y, long long m) {
  if (y == 0) return 1;
  long long p = powmod(x, y / 2, m) % m;
  p = (p * p) % m;
  return (y % 2 == 0) ? p : (x * p) % m;
}
long long modif(long long x, long long m) { return (powmod(x, m - 2, m)); }
bool fa(vector<long long> &x, vector<long long> &y) { return x[0] < y[0]; }
bool fa1(vector<long long> &x, vector<long long> &y) { return x[1] < y[1]; }
bool f1(pair<long long, long long> &x, pair<long long, long long> &y) {
  return x.second > y.second;
}
bool f2(pair<long long, long long> &x, pair<long long, long long> &y) {
  return x.first > y.first;
}
bool f3(long long &x, long long &y) { return x > y; }
const long long maxn = 5e5 + 2;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  set<string> temp;
  long long ans = 0;
  temp.insert(s);
  long long cnt = 1;
  vector<long long> b;
  long long it = 1;
  while (temp.size() != 0 && cnt < k) {
    set<string> g = temp;
    temp.clear();
    for (auto x : g) {
      for (int i = 0; i < x.size(); i++) {
        string r = x;
        string meow = r.erase(i, 1);
        temp.insert(meow);
      }
    }
    long long h = temp.size();
    h = min(h, k - cnt);
    ans += it * h;
    cnt += h;
    it++;
  }
  if (cnt < k) {
    cout << -1;
    exit(0);
  }
  cout << ans;
  return 0;
}
