#include <bits/stdc++.h>
using namespace std;
int K, T, lim[17], ans[11];
long long F[17][11], C[17][11];
long long dp(int len) {
  if (len == 0) return 1;
  memset(F, 0, sizeof(F));
  for (int i = 0; i <= len && i <= lim[0]; ++i) F[0][i] = C[len][i];
  for (int i = 1; i < 16; ++i)
    for (int j = 0; j <= len; ++j)
      for (int k = 0; k <= j && k <= lim[i]; ++k)
        F[i][j] += F[i - 1][j - k] * C[len - (j - k)][k];
  return F[15][len];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> K >> T;
  for (int i = 0; i < 16; ++i) lim[i] = T, C[i][0] = 1;
  for (int i = 1; i < 16; ++i)
    for (int j = 1; j < 11; ++j) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
  int len = 0, k;
  long long tmp;
  while (1) {
    tmp = 0;
    for (int j = 1; j < 16; ++j) {
      --lim[j];
      tmp += dp(len);
      ++lim[j];
      if (tmp >= K) break;
    }
    if (tmp >= K)
      break;
    else
      K -= tmp;
    ++len;
  }
  for (int i = len; i >= 0; --i) {
    for (int j = 0; j < 16; ++j) {
      if (i == len && j == 0) continue;
      if (lim[j] == 0) continue;
      --lim[j];
      tmp = dp(i);
      if (tmp < K) {
        K -= tmp;
        ++lim[j];
      } else {
        ans[i] = j;
        break;
      }
    }
  }
  for (int i = len; i >= 0; --i)
    printf("%c", ans[i] > 9 ? ans[i] - 10 + 'a' : ans[i] + '0');
  puts("");
  return 0;
}
