#include <bits/stdc++.h>
using namespace std;
const int N = 170;
long long C[20][20], k, t, lef[N], ans[N];
inline void init() {
  C[1][0] = C[1][1] = 1;
  for (int i = 2, nn = int(19); i <= nn; ++i) {
    C[i][0] = 1;
    for (int j = 1, nn = int(i); j <= nn; ++j)
      C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
  }
}
inline long long got(int w) {
  static long long f[18][161];
  f[0][0] = 1;
  for (int i = 1, nn = int(16); i <= nn; ++i)
    for (int j = 0, nn = int(w); j <= nn; ++j) {
      f[i][j] = f[i - 1][j];
      for (int l = 1, nn = int(min(j, (int)lef[i - 1])); l <= nn; ++l)
        f[i][j] += 1LL * f[i - 1][j - l] * C[j][l];
    }
  return f[16][w];
}
void dfs(int w, int s) {
  if (!w) return;
  long long tmp = 0, ces;
  for (int i = s, nn = int(15); i <= nn; ++i)
    if (lef[i]) {
      --lef[i], ces = got(w - 1);
      if (tmp + ces >= k) {
        ans[w] = i;
        k -= tmp, dfs(w - 1, 0);
        break;
      } else
        tmp += ces, ++lef[i];
    }
}
inline char out(int x) {
  return (x < 10 ? (char)(x + '0') : (char)(x - 10 + 'a'));
}
int main() {
  init(), cin >> k >> t;
  for (int i = 0, nn = int(16); i < nn; ++i) lef[i] = t;
  long long mw, tmp;
  for (mw = 1;; ++mw) {
    tmp = got(mw), --lef[0];
    tmp -= got(mw - 1), ++lef[0];
    if (tmp < k)
      k -= tmp;
    else {
      dfs(mw, 1);
      break;
    }
  }
  for (int i = mw, nn = int(1); i >= nn; --i) cout << out(ans[i]);
  cout << endl;
  return 0;
}
