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