#include <bits/stdc++.h>
using namespace std;
struct _ {
  _() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin.exceptions(istream::failbit | istream::badbit);
  }
} _;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
template <class T, class second>
void smax(T& a, const second& b) {
  if (b > a) a = b;
}
template <class T, class second>
void smin(T& a, const second& b) {
  if (b < a) a = b;
}
template <class T, class second>
T pop_begin(second& a) {
  auto it = a.begin();
  T ret = *it;
  a.erase(it);
  return ret;
}
int N;
map<tuple<vi, int, bool>, long long> dp;
long long comp(vi nt, int len, bool leading) {
  if (len == 0) return 1;
  sort(nt.begin() + 1, nt.end());
  tuple<vi, int, bool> key(nt, len, leading);
  auto it = dp.find(key);
  if (it != dp.end()) return it->second;
  long long ans = 0;
  for (int i = !leading; i < (16); ++i) {
    if (nt[i]) {
      nt[i]--;
      ans += comp(nt, len - 1, true);
      nt[i]++;
    }
    if (ans > N) {
      ans = N;
      break;
    }
  }
  return dp[key] = ans;
}
char tohex(int j) {
  if (j < 10) return j + '0';
  return j + 'a' - 10;
}
signed main() {
  int T;
  cin >> N >> T;
  vi nt(16, T);
  int len;
  for (len = 1;; ++len) {
    long long ans = comp(nt, len, false);
    if (comp(nt, len, false) >= N) break;
    N -= ans;
  }
  for (int i = 0; i < (len); ++i) {
    for (int j = !i; j < (16); ++j) {
      if (!nt[j]) continue;
      nt[j]--;
      long long ans = comp(nt, len - i - 1, true);
      if (ans >= N) {
        cout << tohex(j);
        break;
      }
      N -= ans;
      nt[j]++;
    }
  }
  cout << endl;
}
