#include <bits/stdc++.h>
using namespace std;
const int MAXC = 16;
int limit[MAXC + 10], k, t;
long long dp[MAXC + 10][MAXC + 10], fac[MAXC + 10];
char op[MAXC + 10] = {'0', '1', '2', '3', '4', '5', '6', '7',
                      '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
void Calc(int n) {
  memset(dp, 0, sizeof dp);
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 15; j++) {
      for (int nex = j + int(j != 0 || i != 0); nex <= 15; nex++) {
        for (int len = 1; len <= limit[nex]; len++) {
          if (i + len > n) break;
          dp[i + len][nex] += dp[i][j] * (fac[i + len] / fac[i] / fac[len]);
        }
      }
    }
  }
}
void Solve(int len) {
  if (len == 0) return;
  int sum = 0;
  for (int j = 0; j <= 15; j++) {
    if (!limit[j]) continue;
    limit[j]--;
    Calc(len - 1);
    int tsum = 0;
    for (int ks = 0; ks <= 15; ks++) tsum += dp[len - 1][ks];
    if (sum + tsum >= k) {
      k -= sum;
      printf("%c", op[j]);
      Solve(len - 1);
      return;
    }
    sum += tsum;
    limit[j]++;
  }
}
int main() {
  scanf("%d%d", &k, &t);
  fac[0] = 1;
  for (int i = 1; i <= 15; i++) fac[i] = fac[i - 1] * i;
  for (int i = 0; i <= 15; i++) limit[i] = t;
  int sum = 0;
  for (int len = 1;; len++) {
    for (int j = 1; j <= 15; j++) {
      limit[j]--;
      Calc(len - 1);
      int tsum = 0;
      for (int ks = 0; ks <= 15; ks++) tsum += dp[len - 1][ks];
      if (sum + tsum >= k) {
        k -= sum;
        printf("%c", op[j]);
        Solve(len - 1);
        return 0;
      }
      sum += tsum;
      limit[j]++;
    }
  }
  return 0;
}
