#include <bits/stdc++.h>
using namespace std;
int freq[16];
long long dp[20][20];
long long factorial(long long n) {
  long long ans = 1;
  for (int i = 2; i <= n; i++) ans *= i;
  return ans;
}
long long nck(long long n, long long k) {
  return factorial(n) / (factorial(k) * factorial(n - k));
}
long long calculate1(int d) {
  if (d == 0) return 1;
  for (int i = 15; i >= 0; i--) {
    for (int j = 1; j <= d; j++) {
      dp[i][j] = 0;
      for (int k = 0; k <= freq[i]; k++) {
        if (j > k) {
          if (i != 15) dp[i][j] += nck(j, k) * dp[i + 1][j - k];
        } else if (j == k) {
          dp[i][j] += 1;
        }
      }
    }
  }
  return dp[0][d];
}
long long calculate(int d, bool zeroToBeCounted) {
  if (zeroToBeCounted)
    return calculate1(d);
  else {
    long long sum1 = 0;
    for (int x = 1; x <= d; x++) {
      for (int i = 1; i < 16; i++) {
        if (freq[i] == 0) continue;
        freq[i]--;
        sum1 += calculate1(x - 1);
        freq[i]++;
      }
    }
    return sum1;
  }
}
char encode(int i) {
  if (i <= 9)
    return (char)(i + '0');
  else
    return (char)('a' + i - 10);
}
string removeLeadingZeros(string &x) {
  int i;
  for (i = 0; i < x.length(); i++) {
    if (x[i] != '0') break;
  }
  if (i == x.length())
    return "0";
  else
    return x.substr(i);
}
string generateNumber(long long k) {
  string ans = "";
  bool zeroToBeCounted = false;
  for (int i = 0; i < 9; i++) {
    long long prefixSum = 0;
    int j;
    for (j = 0; j < 16; j++) {
      if (freq[j] == 0) continue;
      if (j == 0 && !zeroToBeCounted) {
      } else {
        freq[j]--;
      }
      long long temp;
      if (j == 0)
        temp = calculate(9 - i - 1, zeroToBeCounted);
      else
        temp = calculate(9 - i - 1, true);
      if (j == 0 && !zeroToBeCounted) {
      } else
        freq[j]++;
      long long temp2 = prefixSum + temp;
      if (temp2 >= k) break;
      prefixSum = temp2;
    }
    k -= prefixSum;
    if (j == 0) {
      if (zeroToBeCounted) freq[j]--;
    } else {
      freq[j]--;
      zeroToBeCounted = true;
    }
    ans += encode(j);
  }
  return removeLeadingZeros(ans);
}
int main() {
  int k, t;
  cin >> k >> t;
  for (int i = 0; i < 16; i++) freq[i] = t;
  cout << generateNumber(k) << endl;
  return 0;
}
