#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;
stringstream sss;
const long long int B = 16;
long long int K, t;
long long int have[B];
long long int dp[B];
long long int ent[B][B];
string hexchr = "0123456789abcdef";
long long int count(long long int dn) {
  fill(dp, dp + dn + 1, 0);
  dp[0] = 1;
  for (long long int i = (0); i < (B); ++i) {
    for (long long int j = (dn + 1) - 1; j >= (0); --j) {
      for (long long int c = (1); c < (min(j, have[i]) + 1); ++c) {
        dp[j] += dp[j - c] * ent[c][j];
      }
    }
  }
  return dp[dn];
}
void MAIN() {
  fill(ent[0], ent[0] + B, 1);
  for (long long int i = (1); i < (B); ++i) {
    for (long long int j = (1); j < (B); ++j) {
      ent[i][j] = ent[i - 1][j - 1] + ent[i][j - 1];
    }
  }
  cin >> K >> t;
  fill(have, have + B, t);
  bool leading = true;
  long long int k = K;
  long long int dn = 0;
  long long int cnt = 0;
  while (k > cnt) {
    k -= cnt;
    cnt = 0;
    for (long long int i = (1); i < (B); ++i) {
      have[i]--;
      cnt += count(dn);
      have[i]++;
    }
    ++dn;
  }
  for (long long int i = (dn)-1; i >= (0); --i) {
    long long int d = i == dn - 1;
    long long int cnt = 0;
    while (true) {
      while (!have[d]) ++d;
      have[d]--;
      cnt = count(i);
      if (cnt >= k) break;
      k -= cnt;
      have[d++]++;
    }
    cout << hexchr[d];
  }
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(10);
  sss << R"(
1000000 2
    )";
  MAIN();
  return 0;
}
