#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e9 + 7;
int K, t, a[16], n;
long long c[200][200];
long long dp[17][200];
long long sum(long long a, long long b) {
  if (a + b > INF) return INF;
  return a + b;
}
long long solve(int len, bool fl) {
  memset(dp, 0, sizeof(dp));
  dp[0][len] = 1;
  for (int i = 0; i < 16; i++)
    for (int j = 0; j <= len; j++) {
      if (!fl && !i && !j) continue;
      for (int k = 0; k <= min(a[i], j); k++)
        dp[i + 1][j - k] =
            sum(dp[i + 1][j - k], dp[i][j] * c[j - (!fl && !i)][k]);
    }
  return dp[16][0];
}
int ans[200];
void dfs(int len) {
  for (int i = (n == len); i < 16; i++) {
    a[i]--;
    long long p = solve(len - 1, 1);
    if (p >= K) {
      ans[len] = i;
      dfs(len - 1);
      break;
    }
    a[i]++;
    K -= p;
  }
}
int main() {
  scanf("%d%d", &K, &t);
  for (int i = 0; i < 16; i++) a[i] = t;
  c[0][0] = 1;
  for (int i = 1; i <= 16 * t; i++) {
    c[i][0] = 1;
    for (int j = 1; j <= i; j++) c[i][j] = sum(c[i - 1][j - 1], c[i - 1][j]);
  }
  for (int i = 0; i < 16; i++) a[i] = t;
  for (n = 1; n <= 16 * t; n++) {
    long long p = solve(n, 0);
    if (p >= K) break;
    K -= p;
  }
  dfs(n);
  while (n)
    printf("%c", (ans[n] < 10) ? (ans[n] + '0') : (ans[n] - 10 + 'a')), n--;
  return 0;
}
