#include <bits/stdc++.h>
using namespace std;
const int mx = 50;
long long int f[2][mx];
long long int cmb[mx][mx];
int t;
long long int cnt(vector<int> q, int len) {
  memset(f, 0ll, sizeof f);
  int rw = 0;
  f[rw][0] = 1ll;
  for (int i = 0; i < int(q.size()); i++) {
    rw ^= 1;
    f[rw][0] = 1ll;
    for (int l = 1; l <= len; l++) {
      f[rw][l] = 0ll;
      for (int a = 0; a <= q[i] && a <= l; a++) {
        f[rw][l] += f[rw ^ 1][l - a] * cmb[l][a];
      }
    }
  }
  return f[rw][len];
}
long long int nice(int len) {
  long long int ans = 0ll;
  for (int d = 1; d < 16; d++) {
    vector<int> q(16, t);
    q[d]--;
    ans += cnt(q, len - 1);
  }
  return ans;
}
int main() {
  for (int i = 0; i < mx; i++) {
    cmb[i][0] = cmb[i][i] = 1;
    for (int j = 1; j < i; j++) cmb[i][j] = cmb[i - 1][j] + cmb[i - 1][j - 1];
  }
  long long int k;
  scanf("%lld %d", &k, &t);
  int len = 1;
  while (true) {
    long long int c = nice(len);
    if (c < k) {
      k -= c;
      len++;
    } else
      break;
  }
  int from = 1;
  vector<int> q(16, t);
  string ans = "";
  for (int i = 0; i < len; i++) {
    for (int d = from; d < 16; d++)
      if (q[d] > 0) {
        q[d]--;
        long long int c = cnt(q, len - i - 1);
        if (c < k) {
          k -= c;
          q[d]++;
        } else {
          if (d < 10)
            ans.push_back('0' + d);
          else
            ans.push_back('a' + d - 10);
          break;
        }
      }
    from = 0;
  }
  printf("%s\n", ans.c_str());
  return 0;
}
