#include <bits/stdc++.h>
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
using namespace ::std;
const int maxn = 1e6 + 500;
const long long inf = 2e9 + 8;
clock_t tStart;
long long zarb(long long a, long long b) { return min(inf, a * b); }
void jam(unsigned int &a, long long b) { a = min(inf, b + a); }
char getChar(int v) {
  if (v < 10) return (char)(v + '0');
  return (char)(v - 10 + 'a');
}
int t;
map<pair<int, string>, unsigned> ml;
string ves[maxn];
long long ent[50][50];
int cnt;
int findDP(int tol, string vec) {
  if (tol == 0) return 1;
  if (ml.count(make_pair(tol, vec))) return ml[make_pair(tol, vec)];
  unsigned int ansS = 0;
  for (int j = 1; j <= t; j++) {
    if (vec[j]) {
      vec[j]--;
      vec[j - 1]++;
      ansS = findDP(tol, vec);
      vec[j - 1]--;
      vec[0]++;
      if (j <= tol) jam(ansS, zarb(findDP(tol - j, vec), ent[tol][j]));
      vec[0]--;
      vec[j]++;
      ml[make_pair(tol, vec)] = ansS;
      return ansS;
    }
  }
  return 0;
}
string findAnsS(int tol, unsigned int k) {
  int mah[16];
  fill(mah, mah + 16, t);
  string ans;
  for (int i = 0; i < tol; i++) {
    for (int j = 0; j < 16; j++) {
      if (i == 0 && j == 0) continue;
      unsigned int res = 0;
      if (mah[j]) {
        mah[j]--;
        string ver;
        ver.resize(t + 1);
        for (int y = 0; y < 16; y++) {
          ver[mah[y]]++;
        }
        res = findDP(tol - 1 - i, ver);
        mah[j]++;
      }
      if (res >= k) {
        ans += (getChar(j));
        mah[j]--;
        break;
      } else {
        k -= res;
      }
    }
  }
  return ans;
}
int main() {
  ent[0][0] = 1;
  for (int i = 1; i < 50; i++) {
    ent[i][0] = 1;
    ent[i][i] = 1;
    for (int j = 1; j < i; j++) {
      ent[i][j] = min(inf, ent[i - 1][j - 1] + ent[i - 1][j]);
    }
  }
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  unsigned int k;
  cin >> k >> t;
  if (t >= 9) {
    string ans;
    while (k) {
      ans += getChar(k % 16);
      k /= 16;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
  }
  string vec;
  reverse(ves, ves + cnt);
  string last;
  last.resize(t + 1);
  last[t] = 16;
  for (int tol = 1; tol < 100; tol++) {
    unsigned res = (findDP(tol, last) / 16) * 15;
    if (res >= k) {
      cout << findAnsS(tol, k);
      return 0;
    } else {
      k -= res;
    }
  }
}
