#include <bits/stdc++.h>
using namespace std;
long long d, x, y;
void extendedEuclid(long long A, long long B) {
  if (B == 0) {
    d = A;
    x = 1;
    y = 0;
  } else {
    extendedEuclid(B, A % B);
    int temp = x;
    x = y;
    y = temp - (A / B) * y;
  }
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
map<long long, long long> par, val;
void ini() {
  for (long long i = 0; i < 500010; i++) {
    par[i] = i;
  }
}
long long root(long long x) {
  while (par[x] != x) {
    par[x] = par[par[x]];
    x = par[x];
  }
  return x;
}
void uni(long long x, long long y) {
  x = root(x);
  y = root(y);
  par[y] = par[x];
}
int gcdExtended(int a, int b, int *x, int *y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
int modInverse(int b, int m) {
  int x, y;
  int g = gcdExtended(b, m, &x, &y);
  if (g != 1) return -1;
  return (x % m + m) % m;
}
long long isPrime(long long n) {
  if (n == 0 || n == 1) return n;
  if (n % 2 == 0) return (long long)2;
  if (n % 3 == 0)
    return (long long)3;
  else {
    for (long long i = 5; i * i <= n; i += 6) {
      if (n % i == 0) return i;
      if (n % (i + 2) == 0) return (i + 2);
    }
    return n;
  }
}
long long rec(long long n) {
  long long k = n;
  if (!n) return 0;
  while (isPrime(k) != k && k > 0) k--;
  return 1 + rec(n - k);
}
long long div(long long n) {
  long long c = 0;
  while (n > 0) {
    c += n % 10;
    n /= 10;
  }
  return c;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, i, j, k, m;
  string s;
  cin >> n >> k >> s;
  set<string> x;
  queue<string> q;
  q.push(s);
  while (!q.empty()) {
    string t = q.front();
    q.pop();
    if (x.find(t) != x.end()) continue;
    x.insert(t);
    if (x.size() == k) {
      set<string>::iterator itr;
      long long ans = 0;
      for (itr = x.begin(); itr != x.end(); ++itr) {
        string z = *itr;
        ans += n - z.size();
      }
      cout << ans;
      return 0;
    }
    for (i = 0; i < t.size(); i++) {
      string z = t;
      z.erase(z.begin() + i);
      if (x.find(z) == x.end()) q.push(z);
    }
  }
  cout << -1;
}
