#include <bits/stdc++.h>
using namespace std;
int cnt[16];
int a[1010];
set<long long> s[10][2];
map<long long, long long> mp[10][2];
long long cal() {
  long long ans = 0;
  for (int i = 15; i >= 0; i--) {
    ans = ans * 11 + cnt[i];
  }
  return ans;
}
long long dfs(int dep, bool zeros) {
  if (dep == 0) {
    if (a[1] == 0 && !zeros) return 0;
    return 1;
  }
  long long now = cal();
  if (s[dep][zeros].count(now)) {
    return mp[dep][zeros][now];
  }
  long long sum = 0;
  for (int i = 0; i < 16; i++) {
    if (cnt[i] > 0) {
      if (i != 0 || (i == 0 && zeros == 1)) cnt[i]--;
      a[dep] = i;
      sum += dfs(dep - 1, zeros | (i != 0));
      if (i != 0 || (i == 0 && zeros == 1)) cnt[i]++;
    }
  }
  mp[dep][zeros][now] = sum;
  s[dep][zeros].insert(now);
  return sum;
}
bool solve(int dep, long long remain, bool zeros) {
  if (dep == 0) return 1;
  for (int i = 0; i < 16; i++) {
    if (cnt[i] == 0) continue;
    if (i != 0 || (i == 0 && zeros == 1)) cnt[i]--;
    a[dep] = i;
    long long tmp = dfs(dep - 1, zeros | (i != 0));
    if (tmp >= remain) {
      if (solve(dep - 1, remain, zeros | (i != 0))) return 1;
    } else {
      if (i != 0 || (i == 0 && zeros == 1)) cnt[i]++;
      remain -= tmp;
    }
  }
  return 0;
}
int main() {
  long long n;
  int t;
  scanf("%lld%d", &n, &t);
  long long now = 1;
  for (int i = 1; i; i++) {
    memset(a, 0, sizeof(a));
    for (int i = 0; i < 16; i++) cnt[i] = t;
    long long sum = dfs(i, 0);
    if (sum >= n) {
      for (int i = 0; i < 16; i++) cnt[i] = t;
      memset(a, 0, sizeof(a));
      solve(i, n, 0);
      bool flag = 0;
      for (int j = i; j >= 1; j--) {
        if (a[j] != 0) flag = 1;
        if (flag == 1) {
          if (a[j] < 10)
            printf("%d", a[j]);
          else
            printf("%c", a[j] - 10 + 'a');
        }
      }
      return 0;
    }
  }
}
