#include <bits/stdc++.h>
using namespace std;
const int MAXN = 19;
const int B = 16;
const string S = "0123456789abcdef";
map<long long, long long> memo[MAXN];
int dig[MAXN];
long long tenp[B];
vector<char> c;
int m, n;
long long k, ans;
void fast_io() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
void prepare() {
  tenp[0] = 1;
  for (int i = 1; i < B; i++) {
    tenp[i] = (10LL * tenp[i - 1]);
  }
}
long long solve(int pos, long long mask, bool t) {
  if (!pos) return (mask > 0);
  if (!t and memo[pos][mask]) return memo[pos][mask];
  int cnt[MAXN];
  long long cpymask = mask;
  for (int i = 0; i < B; i++) {
    cnt[i] = (cpymask % 10);
    cpymask /= 10;
  }
  long long res = 0;
  int lim = t ? dig[pos] : B - 1;
  for (int i = 0; i <= lim; i++) {
    if (!i and !mask) {
      res += solve(pos - 1, 0, !(i ^ lim) & t);
      continue;
    }
    if (cnt[i] + 1 <= m) res += solve(pos - 1, mask + tenp[i], !(i ^ lim) & t);
  }
  if (!t) memo[pos][mask] = res;
  return res;
}
long long count(long long x) {
  n = 0;
  while (x) {
    dig[++n] = (x % B);
    x /= B;
  }
  return solve(n, 0, 1);
}
long long query(long long lo, long long hi) {
  long long res = -1;
  while (lo <= hi) {
    long long mid = (lo + hi) >> 1;
    if (count(mid) >= k)
      res = mid, hi = mid - 1;
    else
      lo = mid + 1;
  }
  return res;
}
int main() {
  fast_io();
  prepare();
  cin >> k >> m;
  ans = (m == 10) ? k : query(1, 2.9e10);
  while (ans) {
    c.push_back(S[ans % B]);
    ans /= B;
  }
  reverse(c.begin(), c.end());
  for (auto i : c) {
    printf("%c", i);
  }
  return 0;
}
