#include <bits/stdc++.h>
using namespace std;
int K, T, lim[20];
long long DP[20][20], C[20][20];
vector<char> symbol = {'0', '1', '2', '3', '4', '5', '6', '7',
                       '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
int main() {
  cin >> K >> T;
  int i, j, k, len, pos, x;
  C[0][0] = 1;
  for (i = 1; i <= 16; ++i) {
    for (j = 0; j <= i; ++j) {
      C[i][j] = (!j) ? 1 : C[i - 1][j - 1] + C[i - 1][j];
    }
  }
  for (i = 0; i < 16; ++i) lim[i] = T;
  for (len = 1; len <= 20; ++len) {
    memset(DP, 0, sizeof(DP));
    for (i = 0; i <= min(len - 1, lim[0]); ++i) DP[0][i] = C[len - 1][i];
    for (i = 1; i < 16; ++i) {
      for (j = 0; j <= len; ++j) {
        for (k = 0; k <= min(j, lim[i]); ++k) {
          DP[i][j] += DP[i - 1][j - k] * C[len - (j - k)][k];
        }
      }
    }
    if (DP[15][len] >= K) {
      break;
    }
    K -= DP[15][len];
  }
  if (0) cout << "length = " << len << endl;
  if (0) cout << "K = " << K << endl;
  if (0) cout << "sz = " << symbol.size() << endl;
  for (pos = 1; pos <= len; ++pos) {
    int nlen = len - pos;
    for (x = (pos == 1) ? 1 : 0; x < 16; ++x) {
      if (lim[x] <= 0) continue;
      --lim[x];
      memset(DP, 0, sizeof(DP));
      for (i = 0; i <= min(nlen, lim[0]); ++i) DP[0][i] = C[nlen][i];
      for (i = 1; i < 16; ++i) {
        for (j = 0; j <= nlen; ++j) {
          for (k = 0; k <= min(j, lim[i]); ++k) {
            DP[i][j] += DP[i - 1][j - k] * C[nlen - (j - k)][k];
          }
        }
      }
      if (DP[15][nlen] >= K) {
        cout << symbol[x];
        break;
      }
      ++lim[x];
      K -= DP[15][nlen];
    }
  }
}
