#include <bits/stdc++.h>
using namespace std;
long long dp[8 + 1][16 + 1];
long long comb[8 + 2][16 + 1];
void choose() {
  for (int i = 1; i <= 8 + 1; i++) {
    comb[i][0] = 1;
    if (i <= 16) comb[i][i] = 1;
    for (int j = 1; j < i && j <= 16; j++)
      comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
    for (int j = i + 1; j <= 16; j++) comb[i][j] = 0;
  }
}
void calc_dp(long long lim, long long t, int v[16]) {
  for (int i = 0; i <= lim; i++)
    for (int j = 0; j <= 16; j++) dp[i][j] = 0;
  for (int i = 0; i < min(t, lim + 1); i++) {
    int sum = 0;
    for (int j = 0; j < 16; j++) {
      if (v[j] < t - i) sum++;
      dp[i][j] = sum;
    }
  }
  for (int i = 0; i < lim; i++)
    for (int j = 0; j < 16; j++)
      for (int k = j + 1; k < 16; k++)
        for (int l = 1; l <= t - v[k]; l++)
          if (i + l <= lim) dp[i + l][k] += dp[i][j] * comb[i + 1 + l][l];
}
void calc_dp2(long long lim, long long t, int v[16]) {
  for (int i = 0; i <= lim; i++)
    for (int j = 0; j <= 16; j++) dp[i][j] = 0;
  int sum = 0;
  for (int j = 0; j < 16; j++) {
    if (v[j] < t) sum++;
    dp[0][j] = sum;
  }
  for (int i = 1; i < min(t, lim + 1); i++) {
    for (int j = 0; j < 16; j++) {
      if (v[j] < t - i) dp[i][j] = 1;
    }
  }
  for (int i = 1; i <= lim; i++)
    for (int j = 1; j < 16; j++) {
      for (int k = 1; k <= t - v[j]; k++)
        if (i - k >= 0) dp[i][j] += dp[i - k][j - 1] * comb[i + 1][i - k + 1];
      dp[i][j] += dp[i][j - 1];
    }
}
int main() {
  choose();
  long long n, t;
  cin >> n >> t;
  char v[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
                '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
  int cont[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  calc_dp2(8, t, cont);
  dp[0][16] = dp[0][16 - 2];
  for (int i = 1; i <= 8; i++) {
    dp[i][16] = 0;
    for (int k = 1; k <= t; k++)
      if (i - k >= 0) dp[i][16] += dp[i - k][16 - 2] * comb[i][k];
    dp[i][16] += dp[i][16 - 2];
  }
  int s = 0;
  long long sum = 0;
  while (sum + dp[s][16] < n) {
    sum += dp[s][16];
    s++;
  }
  n -= sum;
  string str = "";
  bool first = true;
  while (s >= 0) {
    int j;
    for (j = (first ? 1 : 0); j < 16; j++) {
      if (cont[j] < t) {
        cont[j]++;
        calc_dp2(s - 1, t, cont);
        if (s > 0) {
          if (dp[s - 1][16 - 1] < n) {
            n -= dp[s - 1][16 - 1];
            cont[j]--;
          } else {
            str += v[j];
            break;
          }
        } else {
          if (1 < n) {
            n -= 1;
            cont[j]--;
          } else {
            str += v[j];
            break;
          }
        }
      }
    }
    s--;
    first = false;
  }
  cout << str << endl;
}
