#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
void sc(int &x) {
  register int c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
long long power(long long a, long long b, long long mod) {
  long long res = 1;
  while (b > 0) {
    if (b % 2 != 0) res = (res * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return res;
}
long long gcd(long long a, long long b) {
  return ((b == 0) ? a : gcd(b, a % b));
}
long long dp[10][16], add[10];
int dig[10], nCr[10][10], b[16], n, t, td;
long long mul(int vac, int alpha) {
  int i;
  if (alpha == -1 && vac > 0) return 0;
  if (vac == 0) return 1;
  if (dp[vac][alpha] != -1) return dp[vac][alpha];
  dp[vac][alpha] = 0;
  for (i = 0; i < min(vac, t - b[alpha]) + 1; i++)
    dp[vac][alpha] += nCr[vac][i] * mul(vac - i, alpha - 1);
  return dp[vac][alpha];
}
void convert_hex(long long num) {
  int i;
  for (i = 0; i < 9; i++) {
    dig[i] = num % 16;
    num /= 16;
    td = i;
    if (num == 0) break;
  }
}
void pr_hex(int num) {
  if (num < 10)
    printf("%c", '0' + num);
  else
    printf("%c", 'a' + (num - 10));
}
int main() {
  long long low, mid, high, ans, tot;
  int i, j;
  for (i = 0; i < 10; i++) {
    nCr[i][0] = 1;
    for (j = 1; j < i + 1; j++) nCr[i][j] = nCr[i - 1][j - 1] + nCr[i - 1][j];
  }
  sc(n);
  sc(t);
  for (i = 0; i < 10; i++) {
    memset(b, 0, sizeof(b));
    for (j = 1; j < 16; j++) {
      b[j]++;
      if (b[j] <= t) {
        memset(dp, -1, sizeof(dp));
        add[i] += mul(i, 15);
      }
      b[j]--;
    }
    if (i > 0) add[i] += add[i - 1];
  }
  low = 1, high = (long long)1 << 36 - 1;
  while (low <= high) {
    int flag = 0;
    mid = (low + high) / 2;
    convert_hex(mid);
    tot = (td > 0) ? add[td - 1] : 0;
    memset(b, 0, sizeof(b));
    for (i = td; i > -1; i--) {
      j = 0;
      if (i == td) j = 1;
      for (; j <= dig[i] - 1; j++) {
        b[j]++;
        if (b[j] <= t) {
          memset(dp, -1, sizeof(dp));
          tot += mul(i, 15);
        }
        b[j]--;
      }
      b[dig[i]]++;
      if (b[dig[i]] > t) {
        flag = 1;
        break;
      }
    }
    tot++;
    if (tot > (long long)n)
      high = mid - 1;
    else {
      low = mid + 1;
      if (!flag) ans = mid;
    }
  }
  convert_hex(ans);
  for (i = td; i > -1; i--) pr_hex(dig[i]);
  return 0;
}
