#include <bits/stdc++.h>
using namespace std;
int k, n, t;
long long dp[18][166], C[196][18];
int R[18];
char as[166];
void solve() {
  cin >> k >> t;
  int len = 0;
  C[0][0] = 1;
  int n = k;
  for (int l = (0), lend = (t * 16); l <= lend; ++l) {
    C[l][0] = 1;
    for (int i = (1), iend = (t); i <= iend; ++i)
      C[l][i] = C[l - 1][i - 1] + C[l - 1][i];
  }
  for (int l = (1), lend = (t * 16); l <= lend; ++l) {
    C[l][0] = 1;
    memset(dp, 0, sizeof dp);
    dp[0][0] = 1;
    for (int i = (1), iend = (16); i <= iend; ++i)
      for (int j = (0), jend = (l); j <= jend; ++j) {
        for (int k = (0), kend = (min(j, t)); k <= kend; ++k)
          dp[i][j] = dp[i][j] + dp[i - 1][j - k] * 1ll * C[l - j + k][k];
      }
    if (dp[16][l] / 16 * 15 >= n) {
      len = l;
      break;
    }
    n -= dp[16][l] / 16 * 15;
  }
  for (int i = (1), iend = (16); i <= iend; ++i) R[i] = t;
  for (int i = (len), iend = (1); i >= iend; --i) {
    int mn = (i == len) + 1;
    for (int k = (mn), kend = (16); k <= kend; ++k) {
      --R[k];
      memset(dp, 0, sizeof dp);
      dp[0][0] = 1;
      for (int w = (1), wend = (16); w <= wend; ++w)
        for (int j = (0), jend = (i - 1); j <= jend; ++j) {
          for (int t = (0), tend = (min(j, R[w])); t <= tend; ++t)
            dp[w][j] = dp[w][j] + dp[w - 1][j - t] * 1ll * C[i - 1 - j + t][t];
        }
      if (dp[16][i - 1] >= n) {
        as[len - i + 1] = (k - 1 > 9 ? k - 11 + 'a' : k - 1 + '0');
        break;
      }
      n -= dp[16][i - 1], ++R[k];
    }
  }
  puts(as + 1);
}
signed main() { solve(); }
