#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010, inf = 1e9;
const long long hashmod = 5000007;
struct edge {
  long long too;
  int pre;
} e[hashmod];
int K, T, tot;
int digit[233];
long long mi[233];
int last[hashmod];
bool v[hashmod];
long long f[hashmod];
template <typename T>
inline void read(T &k) {
  int f = 1;
  k = 0;
  char c = getchar();
  while (c < '0' || c > '9') c == '-' && (f = -1), c = getchar();
  while (c <= '9' && c >= '0') k = k * 10 + c - '0', c = getchar();
  k *= f;
}
inline void add(int x, long long y) {
  e[++tot] = (edge){y, last[x]};
  last[x] = tot;
}
inline int geths(long long x) {
  int now = x % hashmod;
  for (int i = last[now]; i; i = e[i].pre)
    if (e[i].too == x) return i;
  add(now, x);
  return tot;
}
inline long long dfs(int pos, long long now, bool limit, bool lead) {
  if (!pos) return 1;
  long long hs = geths(now * 11 + pos);
  if (!limit && !lead && v[hs]) return f[hs];
  int up = limit ? digit[pos] : 15;
  long long ans = 0;
  for (int i = 0; i <= up; i++) {
    int cnt = now / mi[i] % 11;
    if (cnt == T && (!lead || i)) {
      continue;
    }
    ans += dfs(pos - 1, now + mi[i] * (!lead || i), limit && (i == up),
               lead && !i);
  }
  if (!limit && !lead) v[hs] = 1, f[hs] = ans;
  return ans;
}
inline long long solve(long long x) {
  int cnt = 0;
  long long tmp = x;
  while (x) {
    digit[++cnt] = x % 16;
    x /= 16;
  }
  return dfs(cnt, 0, 1, 1) - 1;
}
inline void getans(long long x) {
  int cnt = 0;
  while (x) {
    digit[++cnt] = x % 16;
    x /= 16;
  }
  for (int i = cnt; i; i--)
    if (digit[i] >= 10)
      printf("%c", digit[i] - 10 + 'a');
    else
      printf("%d", digit[i]);
}
int main() {
  read(K);
  read(T);
  mi[0] = 1;
  for (int i = 1; i < 16; i++) mi[i] = mi[i - 1] * 11;
  long long l = K, r = min(1ll * K * 100, (long long)3e10);
  while (l < r) {
    long long mid = (l + r) >> 1;
    if (solve(mid) >= K)
      r = mid;
    else
      l = mid + 1;
  }
  getans(l);
}
