#include <bits/stdc++.h>
using namespace std;
long long k, t, a[((long long)16)], dp[2][((long long)50)],
    c[((long long)50)][((long long)50)];
char ans[((long long)50)];
long long count(bool flg, long long x) {
  memset(dp, 0, sizeof dp);
  dp[0][0] = 1;
  for (int i = ((long long)16) - 1; i >= 0; i--) {
    bool q = (i & 1);
    for (int j = 0; j < ((long long)50); j++) dp[q][j] = dp[!q][j];
    for (int j = 1; j <= a[i]; j++)
      for (int p = j + (i == 0 && flg); p < ((long long)50); p++)
        dp[q][p] += dp[!q][p - j] * c[p - (i == 0 && flg)][j],
            dp[q][p] = min(dp[q][p], ((long long)2e9 + 7));
  }
  if (!flg) return dp[0][x];
  long long res = 0;
  for (int i = 1; i <= x; i++)
    res += dp[0][i], res = min(res, ((long long)2e9 + 7));
  return res;
}
void solve(long long num, bool zero = 1) {
  if (num == 0) return;
  if (zero && count(1, num - 1) >= k) {
    ans[num - 1] = '.';
    solve(num - 1, 1);
    return;
  }
  if (zero) k -= count(1, num - 1);
  for (int i = zero; i < ((long long)16); i++) {
    if (!a[i]) continue;
    char p = (i + '0');
    if (i > 9) p = ((i - 10) + 'a');
    a[i]--;
    if (count(0, num - 1) >= k) {
      ans[num - 1] = p;
      solve(num - 1, 0);
      return;
    }
    k -= count(0, num - 1);
    a[i]++;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> k >> t;
  for (int i = 0; i < ((long long)50); i++) c[i][i] = c[i][0] = 1;
  for (int i = 1; i < ((long long)50); i++)
    for (int j = 1; j < i; j++)
      c[i][j] = min(((long long)2e9 + 7), c[i - 1][j] + c[i - 1][j - 1]);
  for (int i = 0; i < ((long long)16); i++) a[i] = t;
  solve(min(((long long)50), t * 16));
  for (int i = min(((long long)50), t * 16) - 1; i >= 0; i--)
    if (ans[i] != '.') cout << ans[i];
  return 0;
}
