#include <bits/stdc++.h>
using namespace std;
long long n, m, a[23], f[230][230], c[210][210], wei = 1, sum;
long long C(long long n, long long m) { return c[n][m]; }
long long dp(long long x) {
  memset(f, 0, sizeof f);
  for (long long i = 0; i <= a[0]; i++) f[0][i] = C(x, i);
  for (long long i = 1; i <= 15; i++)
    for (long long j = 0; j <= x; j++)
      for (long long k = 0; k <= min(x, a[i]); k++)
        if (j >= k) f[i][j] += f[i - 1][j - k] * C(x - (j - k), k);
  return f[15][x];
}
signed main() {
  cin >> n >> m;
  for (long long i = 0; i <= 200; i++) c[i][0] = 1;
  for (long long i = 1; i <= 200; i++)
    for (long long j = 1; j <= i; j++) c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
  for (long long i = 0; i <= 15; i++) a[i] = m;
  for (;; wei++) {
    sum = 0;
    if (wei == 1)
      sum = 15;
    else
      for (long long i = 1; i <= 15; i++) {
        a[i]--;
        sum += dp(wei - 1);
        a[i]++;
      }
    if (n > sum)
      n -= sum;
    else
      break;
  }
  for (long long i = wei; i >= 1; i--) {
    if (i == 1) {
      for (long long j = 0; j <= 15; j++) {
        if (wei == 1 && j == 0) continue;
        if (a[j] != 0) n--;
        if (!n) {
          if (j < 10)
            cout << j;
          else
            putchar(j - 10 + 'a');
          break;
        }
      }
      break;
    }
    for (long long j = 0; j <= 15; j++) {
      if (j == 0 && i == wei) continue;
      a[j]--;
      sum = dp(i - 1);
      if (n - sum <= 0) {
        if (j < 10)
          cout << j;
        else
          putchar(j - 10 + 'a');
        break;
      } else
        n -= sum;
      a[j]++;
    }
  }
  return 0;
}
