#include <bits/stdc++.h>
using namespace std;
long long c[200][200], k, t, l, x, f[20][200], dem[20];
long long qhd(int l, int d = 0) {
  for (int i = 0; i <= l; i++)
    for (int j = 0; j <= 16; j++) f[j][i] = 0;
  f[0][l] = 1;
  for (int i = 1; i <= 16; i++) {
    for (int j = 0; j <= l; j++) {
      if (f[i - 1][j] == 0) continue;
      for (int k = 0; k <= dem[i]; k++) {
        if (j < k) break;
        f[i][j - k] += f[i - 1][j] * c[j][k];
      }
    }
  }
  if (d == 1) return f[16][0] / 16 * 15;
  return f[16][0];
}
int main() {
  for (int i = 0; i < 200; i++) c[i][0] = 1;
  for (int i = 1; i < 200; i++)
    for (int j = 1; j <= i; j++) c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
  cin >> k >> t;
  for (int i = 1; i <= 16; i++) dem[i] = t;
  for (l = 1;; l++) {
    long long nho = qhd(l, 1);
    if (nho >= k) break;
    k -= nho;
  }
  for (int i = 1; i <= l; i++) {
    for (int j = 1; j <= 16; j++) {
      if (i == 1 && j == 1) continue;
      dem[j]--;
      long long nho = qhd(l - i);
      if (nho >= k) {
        x = j;
        x--;
        if (x < 10)
          cout << x;
        else
          cout << char(87 + x);
        break;
      }
      k -= nho;
      dem[j]++;
    }
  }
}
