#include <bits/stdc++.h>
using namespace std;
long long C[25][25];
void Init() {
  for (int i = 0; i < 25; i++) {
    C[i][0] = C[i][i] = 1;
    for (int j = 1; j < i; j++) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
  }
}
int K, T, lim[17], Ans[25];
long long dp[17][25];
long long solve(int len) {
  memset(dp, 0, sizeof dp);
  dp[0][0] = 1;
  for (int i = 1; i <= 16; i++)
    for (int j = 0; j <= len; j++)
      for (int k = 0; k <= lim[i] && k + j <= len; k++)
        dp[i][j + k] = dp[i][j + k] + dp[i - 1][j] * C[len - j][k];
  return dp[16][len];
}
int main() {
  Init();
  scanf("%d%d", &K, &T);
  for (int i = 1; i <= 16; i++) lim[i] = T;
  int len = 1;
  while (1) {
    long long res = 0;
    if (len == 1)
      res = 15;
    else {
      for (int i = 2; i <= 16; i++) {
        lim[i]--;
        res += solve(len - 1);
        lim[i]++;
      }
    }
    if (K <= res) break;
    K -= res;
    len++;
  }
  for (int i = len; i >= 1; i--) {
    if (i == 1) {
      for (int j = 1; j <= 16; j++) {
        if (j == 1 && len == 1) continue;
        if (lim[j] != 0) K--;
        if (K == 0) {
          Ans[i] = j;
          break;
        }
      }
    } else {
      for (int j = 1; j <= 16; j++) {
        if (i == len && j == 1) continue;
        lim[j]--;
        long long tmp = solve(i - 1);
        if (K > tmp)
          K -= tmp;
        else {
          Ans[i] = j;
          break;
        }
        lim[j]++;
      }
    }
  }
  for (int i = len; i >= 1; i--) {
    if (Ans[i] <= 10)
      printf("%d", Ans[i] - 1);
    else
      printf("%c", Ans[i] - 11 + 'a');
  }
  return 0;
}
