#include <bits/stdc++.h>
using namespace std;
long long int fact[14], dp[12][16];
int a[20], cnt[20];
string help(string s, int digit, int t) {
  char ch;
  if (digit <= 9)
    ch = '0' + digit;
  else
    ch = 'a' + (digit - 10);
  char str[2];
  str[0] = ch;
  str[1] = '\0';
  s = s + (string)str;
  for (int i = 0; i < 16; i++) a[i] = t;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] >= '0' && s[i] <= '9')
      a[s[i] - '0']--;
    else
      a[s[i] - 'a' + 10]--;
  }
  return s;
}
long long int C(int n, int r) {
  if (r > n) return 0;
  return fact[n] / (fact[r] * fact[n - r]);
}
long long int f(int n, int d) {
  if (n == 0) return 1;
  if (d >= 16) return 0;
  if (dp[n][d] != -1) return dp[n][d];
  long long int ret = 0;
  int i;
  for (i = 0; i <= a[d] && i <= n; i++) {
    if (d == 0 && i == n) continue;
    if (d == 0) ret += f(n - i, d + 1) * C(n - 1, i);
    if (d != 0) ret += f(n - i, d + 1) * C(n, i);
  }
  return ret;
}
long long int g(int n) {
  int can_use = a[0];
  long long int ret = 0;
  for (int i = 0; i <= n; i++) {
    if (can_use >= (n - i)) {
      memset(dp, -1, sizeof(dp));
      a[0] = can_use - (n - i);
      ret += f(i, 0);
    }
  }
  return ret;
}
int main() {
  int i, j, l, m, n, t;
  long long int k;
  fact[0] = 1;
  for (i = 1; i <= 12; i++) fact[i] = (fact[i - 1] * (long long int)i);
  cin >> k >> t;
  for (i = 0; i <= 15; i++) a[i] = t;
  memset(dp, -1, sizeof(dp));
  for (i = 1; i <= 10; i++) {
    if (f(i, 0) >= k)
      break;
    else
      k -= f(i, 0);
  }
  l = i;
  string s = "";
  for (i = 1; i <= l; i++) {
    for (j = 0; j <= 15; j++) {
      if (j == 0 && s == "") continue;
      if (cnt[j] >= t) continue;
      help(s, j, t);
      long long int ret = g(l - i);
      if (ret >= k)
        break;
      else
        k -= ret;
    }
    cnt[j]++;
    s = help(s, j, t);
  }
  cout << s << endl;
  return 0;
}
