#include <bits/stdc++.h>
using namespace std;
int k, t;
long long C[20][20];
inline long long calc(int w, vector<int>& v) {
  static long long f[20];
  memset(f, 0, sizeof f);
  *f = 1;
  for (int x : v) {
    static long long g[20];
    memset(g, 0, sizeof g);
    for (int d = 0; d <= x; ++d)
      for (int i = w; i >= d; --i) g[i] += f[i - d] * C[w - i + d][d];
    memcpy(f, g, sizeof f);
  }
  return f[w];
}
string solve(int w, int k, vector<int>& v, bool flag = 0) {
  if (!w) return "";
  for (int s = flag; s < 16; ++s)
    if (v[s]) {
      --v[s];
      long long tot = calc(w - 1, v);
      if (tot >= k) {
        char vs = s < 10 ? (s ^ '0') : (s - 10 + 'a');
        return vs + solve(w - 1, k, v);
      }
      k -= tot;
      ++v[s];
    }
  exit(233);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> k >> t;
  **C = 1;
  for (int i = 1; i < 20; ++i) {
    C[i][0] = 1;
    for (int j = 1; j <= i; ++j) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
  }
  vector<int> vc;
  for (int i = 0; i < 16; ++i) vc.push_back(t);
  for (int w = 1;; ++w) {
    --vc[1];
    long long tot = calc(w - 1, vc) * 15;
    ++vc[1];
    if (tot >= k) {
      cout << solve(w, k, vc, 1) << '\n';
      return 0;
    }
    k -= tot;
  }
  return 114514;
}
