#include <bits/stdc++.h>
using namespace std;
int K, T;
map<pair<int, vector<int> >, long long> M;
long long numInt(int dig, vector<int> left) {
  if (M.find(make_pair(dig, left)) != M.end()) return M[make_pair(dig, left)];
  if (dig == 0) {
    M[make_pair(dig, left)] = 1;
    return 1;
  }
  long long ans = 0;
  for (int i = 0; i < 16; i++) {
    if (left[i] == 0) continue;
    vector<int> nxt = left;
    nxt[i]--;
    sort(nxt.begin(), nxt.end());
    ans += numInt(dig - 1, nxt);
  }
  M[make_pair(dig, left)] = ans;
  return ans;
}
long long numInt(int dig, int num) {
  vector<int> v;
  for (int i = 0; i < 16; i++) v.push_back(num);
  v[0]--;
  return 15 * numInt(dig - 1, v);
}
string s;
char hex(int i) {
  if (i < 10)
    return (char)(i + '0');
  else
    return (char)((i - 10) + 'a');
}
void calc(int dig, vector<int> v, int k) {
  if (dig == 0) return;
  for (int i = 0; i < 16; i++) {
    if (v[i] == 0) continue;
    vector<int> w = v;
    w[i]--;
    long long p = numInt(dig - 1, w);
    if (k <= p) {
      s += hex(i);
      calc(dig - 1, w, k);
      break;
    } else
      k -= p;
  }
}
int main() {
  cin >> K >> T;
  int dig = 1;
  while (numInt(dig, T) < K) {
    K -= numInt(dig, T);
    dig++;
  }
  vector<int> v;
  for (int i = 0; i < 16; i++) v.push_back(T);
  v[0]--;
  long long p = numInt(dig - 1, v);
  for (int i = 1; i < 16; i++) {
    if (K <= p) {
      s += hex(i);
      vector<int> w;
      for (int j = 0; j < 16; j++) w.push_back(T);
      w[i]--;
      calc(dig - 1, w, K);
      break;
    }
    K -= p;
  }
  cout << s << '\n';
}
