#include <bits/stdc++.h>
using namespace std;
long long c[20][20], dp[20][20], size;
int k, t, deep, a[20];
void db() {
  c[1][0] = 1;
  c[1][1] = 1;
  for (int i = 2; i <= 10; i++) {
    c[i][0] = 1;
    for (int j = 1; j <= i; j++) {
      c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
    }
  }
}
long long dp_(int x) {
  for (int i = 0; i <= 16; i++) {
    dp[0][i] = 1;
  }
  for (int i = 1; i <= x; i++) {
    for (int j = 1; j <= 16; j++) {
      dp[i][j] = 0;
      for (int k = 0; k <= min(i, a[j]); k++) {
        dp[i][j] += dp[i - k][j - 1] * c[i][k];
      }
    }
  }
  return dp[x][16];
}
void output(int x) {
  if (x < 10) {
    printf("%c", x + '0');
  } else {
    printf("%c", x - 10 + 'a');
  }
}
void dfs(int k, int x) {
  if (x == 0) {
    return;
  }
  int i = 0;
  if (x == deep) {
    i = 2;
  } else {
    i = 1;
  }
  for (; i <= 16; i++) {
    if (a[i] == 0) {
      continue;
    }
    a[i]--;
    size = dp_(x - 1);
    if (size >= k) {
      output(i - 1);
      dfs(k, x - 1);
      break;
    }
    k -= size;
    a[i]++;
  }
}
int main() {
  scanf("%d %d", &k, &t);
  db();
  for (int i = 1; i <= 16; i++) {
    a[i] = t;
  }
  deep = 1;
  while (1) {
    a[2]--;
    size = dp_(deep - 1) * 15;
    a[2]++;
    if (size >= k) {
      break;
    }
    deep++;
    k -= size;
  }
  dfs(k, deep);
  return 0;
}
