#include <bits/stdc++.h>
using namespace std;
const long long inf = 2e9 + 10;
char Hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
                '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
long long cnt[17], dp[17][17], C[17][17], k, t, flag;
long long f(long long n) {
  if (n == 0) return 1;
  memset(dp, 0, sizeof dp);
  for (long long i = 1; i <= 16; i++) {
    dp[i - 1][0] = 1;
    for (long long j = 1; j <= n; j++)
      for (long long k = 0; k <= min(cnt[i - 1], j); k++)
        dp[i][j] += dp[i - 1][j - k] * C[j][k], dp[i][j] = min(dp[i][j], inf);
  }
  if (flag || cnt[0] == 0) return dp[16][n];
  long long r1 = dp[16][n];
  cnt[0]--;
  flag = 1;
  long long r2 = f(n - 1);
  flag = 0;
  cnt[0]++;
  return r1 - r2;
}
int32_t main() {
  for (long long i = 0; i < 17; i++) C[i][0] = 1;
  for (long long i = 1; i < 17; i++)
    for (long long j = 1; j < 17; j++) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
  cin >> k >> t;
  for (long long j = 0; j < 16; j++) cnt[j] = t;
  long long n = 1;
  while (f(n) < k) k -= f(n), n++;
  flag = 1;
  for (long long i = 0, j; i < n; i++) {
    for (j = (i == 0); j < 16; j++)
      if (cnt[j]) {
        cnt[j]--;
        if (f(n - i - 1) >= k) break;
        k -= f(n - i - 1);
        cnt[j]++;
      }
    cout << Hex[j];
  }
  cout << "\n";
  return 0;
}
