#include <bits/stdc++.h>
using namespace std;
vector<long long> fact = {1};
long long factorial(int f) {
  while (fact.size() <= f) fact.push_back(fact.back() * fact.size());
  return fact[f];
}
long long permute(int sum, vector<int> &used, bool lead_zero) {
  long long res = factorial(sum);
  for (int v : used) res /= factorial(v);
  if (!lead_zero) {
    res *= sum - used[0];
    res /= sum;
  }
  return res;
}
long long dfs(vector<int> &can, vector<int> &fit, vector<int> &used, int sum,
              int need, int lvl, bool lead_zero) {
  if (need < 0 || fit[lvl] < need) return 0;
  if (lvl == 15) {
    used[15] = need;
    return permute(sum, used, lead_zero);
  }
  long long res = 0;
  for (used[lvl] = 0; used[lvl] <= can[lvl]; used[lvl]++) {
    res += dfs(can, fit, used, sum, need - used[lvl], lvl + 1, lead_zero);
  }
  return res;
}
long long ways(vector<int> left, int digs, bool lead_zero) {
  ;
  ;
  vector<int> fit = left;
  for (int d = 14; d >= 0; d--) fit[d] += fit[d + 1];
  vector<int> used(16, 0);
  long long ret = dfs(left, fit, used, digs, digs, 0, lead_zero);
  ;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);
  int K, T;
  cin >> K >> T;
  int D = 1;
  vector<int> left(16, T);
  while (true) {
    long long dw = ways(left, D, false);
    if (dw < K) {
      K -= dw;
      D++;
    } else
      break;
  }
  vector<int> ans(D);
  for (int i = 0; i < D; i++) {
    for (ans[i] = (i ? 0 : 1); ans[i] < 16; ans[i]++) {
      left[ans[i]]--;
      long long rest = ways(left, D - i - 1, true);
      if (rest < K) {
        K -= rest;
        left[ans[i]]++;
      } else
        break;
    }
  }
  string digs = "0123456789abcdef";
  for (int v : ans) {
    cout << digs[v];
  }
  cout << endl;
  return 0;
}
