#include <bits/stdc++.h>
using namespace std;
int ncr[9][9];
long long numdig[10];
int cnt[16];
long long dp[10][16];
long long k;
int t;
vector<int> an;
long long go(int left, int largest) {
  if (left == 0) {
    return 1;
  }
  if (largest == -1 && left > 0) {
    return 0;
  }
  if (dp[left][largest] != -1) {
    return dp[left][largest];
  }
  int lim = min(left, t - cnt[largest]);
  long long ans = 0;
  for (int i = 0; i <= lim; i++) {
    ans += (ncr[left][i] * go(left - i, largest - 1));
  }
  return ans;
}
long long solve(int dig) {
  long long ans = 0;
  for (int i = 1; i <= 15; i++) {
    cnt[i] = 1;
    ans += go(dig - 1, 15);
    cnt[i] = 0;
  }
  return ans;
}
int nod;
int main() {
  scanf("%lld %d", &k, &t);
  for (int i = 0; i < 9; i++) {
    ncr[i][0] = 1;
    for (int j = 1; j <= i; j++) {
      ncr[i][j] = ncr[i - 1][j - 1] + ncr[i - 1][j];
    }
  }
  for (int i = 1; i <= 9; i++) {
    for (int j = 0; j < 9; j++) {
      for (int k = 0; k < 16; k++) {
        dp[j][k] = -1;
      }
    }
    numdig[i] = solve(i);
  }
  long long cur = 0;
  nod = 0;
  for (int i = 0; i <= 9; i++) {
    cur += numdig[i];
    if (cur >= k) {
      nod = i;
      cur -= numdig[i];
      break;
    }
  }
  for (int i = 1; i <= nod; i++) {
    for (int j = 0; j <= 15; j++) {
      if (i == 1 && j == 0) {
        continue;
      }
      for (int l = 0; l < 9; l++) {
        for (int k = 0; k < 16; k++) {
          dp[l][k] = -1;
        }
      }
      if (cnt[j] < t) {
        cnt[j]++;
        long long temp = go(nod - i, 15);
        cur += temp;
        if (cur >= k) {
          cur -= temp;
          an.push_back(j);
          break;
        } else {
          cnt[j]--;
        }
      }
    }
  }
  for (int i = 0; i < nod; i++) {
    if (an[i] <= 9) {
      printf("%d", an[i]);
    } else {
      printf("%c", (an[i] - 10) + 'a');
    }
  }
}
