#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
using ii = pair<int, int>;
using ll = long long;
const int N = 20;
const int mod = 1e9 + 7;
int C[N][N];
ll k;
int t;
int ans[N];
ll solve(int n, vector<int>& v, bool f = false) {
  if (f && v[0] <= 0) return 0;
  for (int i = 0; i < v.size(); i++) {
    if (v[i] < 0) return 0;
  }
  vector<ll> dp(n + 1, 0);
  dp[n - f] = 1;
  for (int i = 0; i < v.size(); i++)
    for (int j = 0; j <= n; j++)
      for (int k = 1; k <= j && k <= v[i] - (f && i == 0); k++)
        dp[j - k] += dp[j] * C[j][k];
  return dp[0];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  scanf("%lld%d", &k, &t);
  for (int i = 0; i < N; i++)
    for (int j = 0; j <= i; j++)
      C[i][j] = (j == 0 ? 1 : C[i - 1][j] + C[i - 1][j - 1]);
  int len = 1;
  vector<int> cur(16, t);
  while (true) {
    ll x = solve(len, cur) - solve(len, cur, true);
    if (x >= k) break;
    k -= x;
    len++;
  }
  for (int i = 0; i < len; i++) {
    for (int j = i == 0; j < 16; j++) {
      cur[j]--;
      ll x = solve(len - i - 1, cur);
      if (x >= k) {
        printf("%x", j);
        break;
      }
      k -= x;
      cur[j]++;
    }
  }
  return 0;
}
