#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int dx[] = {0, 0, 1, -1, -1, 1, -1, 1};
int dy[] = {-1, 1, 0, 0, 1, 1, -1, -1};
int dz[] = {0, 0, 1, -1, -1, 1, -1, 1};
int kx[] = {2, 2, -2, -2, 1, -1, 1, -1};
int ky[] = {1, -1, 1, -1, 2, 2, -2, -2};
template <typename T>
void print(const T& x) {
  cerr << x << ' ';
}
template <typename T1, typename... T2>
void print(const T1& first, const T2&... rest) {
  print(first);
  print(rest...);
}
bool isPal(string s) {
  int half = s.size() / 2;
  for (int i = 0, j = s.size() - 1; i < half; i++, j--)
    if (s[i] != s[j]) return false;
  return true;
}
double _distance(double x1, double y1, double x2, double y2) {
  double x1x2 = x1 - x2;
  double y1y2 = y1 - y2;
  return sqrt((x1x2 * x1x2) + (y1y2 * y1y2));
}
bool inBound(int x, int y, int r, int c) {
  return (x >= 0 && x < r && y >= 0 && y < c);
}
long long mulmod(long long a, long long b, long long c) {
  long long x = 0, y = a % c;
  while (b > 0) {
    if (b & 1) x = (x + y) % c;
    y = (y << 1) % c;
    b >>= 1;
  }
  return x % c;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  int n, k;
  string s;
  cin >> n >> k >> s;
  set<string> st;
  queue<string> q;
  q.push(s);
  st.insert(s);
  while (q.size() && int(st.size()) < k) {
    string u = q.front();
    q.pop();
    for (int i = 0; u[i]; i++) {
      string v = u;
      v.erase(i, 1);
      if (!st.count(v) && int(st.size()) < k) {
        st.insert(v);
        q.push(v);
      }
    }
  }
  if (int(st.size()) == k) {
    int ans = 0;
    for (auto it : st) ans += (n - it.size());
    cout << ans << endl;
  } else
    cout << "-1" << endl;
  return 0;
}
