#include <bits/stdc++.h>
using namespace std;
long long f[20][20], g[20];
int n, m, z, x, y, cnt[20], len;
long long C(long long n, long long m) {
  if (m == 0) return 1;
  if (n < m) return 0;
  long long ans = 1;
  for (long long i = m + 1; i <= n; ++i) ans *= i;
  for (long long i = 1; i <= n - m; ++i) ans /= i;
  return ans;
}
long long DP(int w) {
  if (w == 0) return 1;
  memset(f, 0, sizeof(f));
  f[0][0] = 1;
  for (int i = 1; i <= 16; ++i)
    for (int j = 0; j <= w; ++j)
      for (int k = 0; k <= cnt[i]; ++k)
        if (j >= k) f[i][j] += f[i - 1][j - k] * C(w - (j - k), k);
  return f[16][w];
}
void PR(int x) {
  if (x <= 10)
    printf("%d", x - 1);
  else
    printf("%c", x - 11 + 'a');
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= 16; ++i) cnt[i] = m;
  x = 0;
  z = 0;
  while (z + f[16][x] / 16 * 15 < n) {
    z += f[16][x] / 16 * 15;
    DP(++x);
  }
  len = x;
  for (; x > 0; --x) {
    for (int j = 1; j <= 16; ++j)
      if (cnt[j] > 0 && (j != 1 || x != len)) {
        --cnt[j];
        y = DP(x - 1);
        ++cnt[j];
        if (z + y >= n) {
          --cnt[j];
          PR(j);
          break;
        }
        z += y;
      }
  }
}
