#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T GCD(T a, T b) {
  a = abs(a);
  b = abs(b);
  while (b) {
    a = a % b;
    swap(a, b);
  }
  return a;
}
template <typename T>
inline T LCM(T x, T y) {
  T tp = GCD(x, y);
  if ((x / tp) * 1. * y > 9e18) return 9e18;
  return (x / tp) * y;
}
template <typename T>
inline T BigMod(T A, T B, T M) {
  T ret = 1;
  while (B) {
    if (B & 1) ret = (ret * A) % M;
    A = (A * A) % M;
    B = B >> 1;
  }
  return ret;
}
template <typename T>
inline T InvMod(T A, T M) {
  return BigMod(A, M - 2, M);
}
long long gcdr(long long a, long long b) {
  if (a == 0) return b;
  return gcdr(b % a, a);
}
long long max(long long a, long long b) {
  if (a > b) return a;
  return b;
}
long long min(long long a, long long b) {
  if (a < b) return a;
  return b;
}
void FastIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
}
const long long size3 = 300005;
const long long size2 = 200005;
const long long size1 = 100005;
long long n, m;
string s;
bool done = false;
set<string> allStrings;
map<string, long long> M;
string toString(long long i) {
  string x = "";
  if (i < 10) {
    x += (i + '0');
    return x;
  }
  while (i) {
    x += ((i % 10) + '0');
    i = i / 10;
  }
  return x;
}
void rec(long long sz, long long currentIndex, string currentString) {
  currentString += s[currentIndex];
  if (done) return;
  if ((currentIndex + (sz - currentString.size())) - 1 >= n) return;
  if (currentString.size() == sz) {
    allStrings.insert(currentString);
    if (allStrings.size() == m) done = true;
    return;
  }
  string x = toString(sz);
  if (M[currentString + x] == 1) {
    return;
  }
  M[currentString + x] = 1;
  long long arr[30] = {0};
  for (long long i = currentIndex + 1; i < n && !done; i++) {
    if (arr[s[i] - 'a'] == 0) {
      rec(sz, i, currentString);
      arr[s[i] - 'a'] = 1;
    }
  }
}
int main() {
  long long t, i, j, x, y;
  t = 1;
  while (t--) {
    cin >> n >> m;
    cin >> s;
    for (i = n; i > 0 && !done; i--) {
      long long arr[30] = {0};
      for (j = 0; j < n && !done; j++) {
        if (arr[s[j] - 'a'] == 0) {
          string ss = "";
          rec(i, j, ss);
          arr[s[j] - 'a'] = 1;
        }
      }
    }
    long long ans = 0;
    for (auto it = allStrings.begin(); it != allStrings.end(); ++it) {
      string q = *it;
      ans += (n - q.size());
    }
    if (allStrings.size() < m) {
      ans += n;
    }
    if ((allStrings.size() + 1) < m) {
      cout << -1 << endl;
    } else
      cout << ans << endl;
  }
  return 0;
}
