#include <bits/stdc++.h>
using namespace std;
long long int solution(vector<long long int>& A, long long int k) {
  const long long int N = A.size();
  if (N < k || N < 1 || k < 1) return 0;
  if (N == k) return 1;
  vector<long long int> v1(N, 0);
  vector<long long int> v2(N, 0);
  vector<long long int> v3(N, 0);
  v2[N - 1] = 1;
  v3[A[N - 1] - 1] = 1;
  for (long long int i = N - 2; i >= 0; i--) {
    v2[i] = v2[i + 1];
    if (v3[A[i] - 1] == 0) {
      v2[i]++;
      v3[A[i] - 1] = 1;
    }
  }
  for (long long int j = 1; j < k; j++) {
    fill(v3.begin(), v3.end(), 0);
    v1[N - 1] = 0;
    for (long long int i = N - 2; i >= 0; i--) {
      v1[i] = v1[i + 1];
      v1[i] = v1[i] + v2[i + 1];
      v1[i] = v1[i] - v3[A[i] - 1];
      v3[A[i] - 1] = v2[i + 1];
    }
    v2 = v1;
  }
  return v1[0];
}
long long int solve(long long int a[], long long int n, long long int k) {
  vector<long long int> v;
  v.assign(a, a + n);
  return solution(v, k);
}
vector<pair<long long int, long long int> > v;
long long int dp[107][107];
long long int fun(long long int idx, long long int k, long long int n,
                  long long int cost) {
  if (idx == n + 1) {
    if (k == 0) {
      return cost;
    } else {
      return INT_MAX;
    }
  }
  if (dp[idx][k] != -1) {
    return dp[idx][k];
  }
  long long int res = fun(idx + 1, k, n, cost);
  for (long long int i = 1; i < min(k, v[idx].first) + 1; ++i) {
    res = min(res, fun(idx + 1, k - i, n, cost + i * v[idx].second));
  }
  return dp[idx][k] = res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, k;
  string str;
  cin >> n >> k;
  cin >> str;
  long long int a[n];
  unordered_map<char, long long int> p;
  vector<long long int> tmp;
  for (long long int i = 0; i < n; ++i) {
    if (p.find(str[i]) == p.end()) {
      tmp.push_back((str[i] - 'a'));
      p[str[i]]++;
    }
  }
  sort(tmp.begin(), tmp.end());
  for (long long int i = 0; i < n; ++i) {
    a[i] =
        lower_bound(tmp.begin(), tmp.end(), (str[i] - 'a')) - tmp.begin() + 1;
  }
  v.push_back({1, n});
  v.push_back({tmp.size(), n - 1});
  for (long long int i = 2; i < n + 1; ++i) {
    v.push_back({solve(a, n, i), n - i});
  }
  memset(dp, -1, sizeof(dp));
  long long int res = fun(0, k, n, 0);
  if (res == INT_MAX) {
    res = -1;
  }
  cout << res << endl;
  return 0;
}
