#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int k, t;
long long ele[12], hash_val;
int freq[20], cnt[12];
map<pair<int, long long>, long long> vis;
void add(int x) {
  cnt[freq[x]]--;
  hash_val -= ele[freq[x]];
  freq[x]++;
  cnt[freq[x]]++;
  hash_val += ele[freq[x]];
}
void remove(int x) {
  cnt[freq[x]]--;
  hash_val -= ele[freq[x]];
  freq[x]--;
  cnt[freq[x]]++;
  hash_val += ele[freq[x]];
}
long long find(int x) {
  if (x == 0) return 1ll;
  long long ans = 0;
  auto state = make_pair(x, hash_val);
  if (vis.count(state) != 0) return vis[state];
  for (int i = 0; i < 16; i++) {
    if (freq[i] < t) {
      add(i);
      ans += find(x - 1);
      remove(i);
    }
  }
  vis[state] = ans;
  return ans;
}
int main() {
  cnt[0] = 16;
  hash_val = 16;
  ele[0] = 1;
  for (int i = 1; i <= 10; i++) ele[i] = 17 * ele[i - 1];
  scanf("%d%d", &k, &t);
  add(1);
  int n = 0;
  long long x;
  for (int i = 1; i <= 10; i++) {
    x = 15ll * find(i - 1);
    if (x >= k) {
      n = i;
      break;
    } else
      k -= x;
  }
  remove(1);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 16; j++) {
      if (i == 1 and j == 0) continue;
      if (freq[j] >= t) continue;
      add(j);
      x = find(n - i);
      if (x >= k) {
        printf("%c", (j > 9) ? 'a' + j - 10 : j + '0');
        break;
      } else
        k -= x;
      remove(j);
    }
  }
  printf("\n");
}
