#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int N = 100005;
int a[9];
int t;
int b[16];
long long dp[8][16];
long long c[9][9];
long long go(int p, int x) {
  if (p == -1) return 1;
  if (x == 0) {
    if (t - b[x] >= p + 1) return 1;
    return 0;
  }
  long long &res = dp[p][x];
  if (res >= 0) return res;
  res = 0;
  for (int i = 0; i <= (min(p + 1, t - b[x])); ++i) {
    res += c[p + 1][i] * go(p - i, x - 1);
  }
  return res;
}
char hex(int x) {
  if (x >= 10) return 'a' + (x - 10);
  return '0' + x;
}
long long g[9];
long long f(int x) {
  long long res = 0;
  memset(b, 0, sizeof(b));
  for (int i = 1; i <= (15); ++i) {
    memset(dp, -1, sizeof(dp));
    b[i]++;
    res += go(x - 1, 15);
    b[i]--;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long k;
  cin >> k >> t;
  for (int i = 0; i <= (8); ++i) {
    c[i][0] = 1;
    for (int j = 1; j <= (i); ++j) {
      c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
    }
  }
  for (int i = 0; i <= (8); ++i) {
    g[i] = f(i);
    if (i > 0) g[i] += g[i - 1];
  }
  long long lo = 1, hi = (1LL << 36) - 1;
  while (lo < hi) {
    long long mi = (lo + hi) / 2;
    long long p = mi + 1;
    int td = 0;
    for (int i = 0; i <= (8); ++i) {
      a[i] = p % 16;
      p /= 16;
      td = i;
      if (p == 0) {
        break;
      }
    }
    long long tot = td > 0 ? g[td - 1] : 0;
    memset(b, 0, sizeof(b));
    for (int i = (td); i >= 0; --i) {
      for (int j = (i == td) ? 1 : 0; j <= (a[i] - 1); ++j) {
        b[j]++;
        if (b[j] <= t) {
          memset(dp, -1, sizeof(dp));
          tot += go(i - 1, 15);
        }
        b[j]--;
      }
      b[a[i]]++;
      if (b[a[i]] > t) break;
    }
    if (tot >= k)
      hi = mi;
    else
      lo = mi + 1;
  }
  vector<int> ans;
  while (lo > 0) {
    ans.push_back(lo % 16);
    lo /= 16;
  }
  reverse(ans.begin(), ans.end());
  for (auto &&x : ans) {
    cout << hex(x);
  }
  cout << endl;
  return 0;
}
