#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int N, k, limit[16], answer[16];
bool mark[16][16];
long long dp[16][16], ente[16][16];
long long mem(int n, int c) {
  if (c == 16) return (n == 0) ? 1 : 0;
  if (mark[n][c]) return dp[n][c];
  for (int i = 0; i <= min(n, limit[c]); i++)
    dp[n][c] += ente[i][n] * mem(n - i, c + 1);
  mark[n][c] = true;
  return dp[n][c];
}
inline long long get_(int n, int c) {
  memset(mark, 0, sizeof(mark));
  memset(dp, 0, sizeof(dp));
  return mem(n, c);
}
long long nozero(int l) {
  long long local = get_(l, 0);
  limit[0]--;
  local -= get_(l - 1, 0);
  limit[0]++;
  return local;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N >> k;
  for (int i = 0; i < 16; i++) {
    for (int j = 1; j < i; j++)
      ente[j][i] = ente[j][i - 1] + ente[j - 1][i - 1];
    ente[0][i] = ente[i][i] = 1;
  }
  fill(limit, limit + 16, k);
  int l = 1;
  while (nozero(l) < N) N -= nozero(l++);
  for (int i = l - 1; ~i; i--) {
    for (int j = (i == (l - 1)) ? 1 : 0; j < 16; j++) {
      limit[j]--;
      answer[i] = j;
      long long local = get_(i, 0);
      if (local < N) {
        limit[j]++;
        N -= local;
      } else
        break;
    }
  }
  for (int i = l - 1; ~i; i--) {
    if (answer[i] < 10)
      cout << answer[i];
    else
      cout << (char)('a' + answer[i] - 10);
  }
  return 0;
}
