#include <bits/stdc++.h>
using namespace std;
const int maxn = 20 + 5;
const long long INF = 3e9;
const char *cc = "0123456789abcdef";
int c[maxn][maxn], used[maxn];
long long dp[maxn][maxn];
char s[maxn];
long long solve(int t, int m, bool flag) {
  memset(dp[0], 0, sizeof(dp[0]));
  if (flag) {
    for (int i = 0; i < m; ++i) {
      for (int j = 0; j + used[0] <= t && j + i + 1 <= m; ++j) {
        dp[0][i + j] = min(INF, dp[0][i + j] + c[m - i - 1][j]);
      }
    }
  } else
    for (int i = 0; i + used[0] <= t && i <= m; ++i) dp[0][i] = c[m][i];
  for (int i = 1; i < 16; ++i) {
    memset(dp[i], 0, sizeof(dp[i]));
    for (int j = 0; j <= m; ++j) {
      if (!dp[i - 1][j]) continue;
      for (int k = 0; k + used[i] <= t && k + j <= m; ++k) {
        dp[i][j + k] = min(INF, dp[i][j + k] + dp[i - 1][j] * c[m - j][k]);
      }
    }
  }
  return dp[15][m];
}
int main() {
  for (int i = 0; i < maxn; ++i) {
    c[i][0] = c[i][i] = 1;
    for (int j = 1; j < i; ++j) c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
  }
  int k, t;
  cin >> k >> t;
  bool flag = true;
  for (int i = 0; i < 20; ++i) {
    long long sum = 0;
    for (int j = 0; j < 16; ++j) {
      if (used[j] >= t) continue;
      if (!flag || j != 0) ++used[j];
      long long tmp = solve(t, 20 - i - 1, flag && j == 0);
      sum += tmp;
      if (sum >= k) {
        s[i] = cc[j];
        k -= sum - tmp;
        if (j > 0) flag = false;
        break;
      }
      if (!flag || j != 0) --used[j];
    }
  }
  s[20] = 0;
  int p = 0;
  while (s[p] == '0') ++p;
  cout << s + p << endl;
  return 0;
}
