#include <bits/stdc++.h>
using namespace std;
const long long N = 30;
const long long M = 16;
const long long mod = 998244353;
const long long MOD = 998244353;
const long double eps = 0.000000001;
const long long P = 1336;
const long long inf = 1e16;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
long long need, t;
long long cnt[N], f[N], dp[N][N], dp2[N][N];
long long solve(long long n, bool fl) {
  if (n <= 0) return 1;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < M; j++) {
      dp[i][j] = 0;
    }
  }
  for (long long i = 0; i < M; i++) {
    for (long long j = 0; j < cnt[i]; j++) {
      dp[j][i] = 1;
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < M - 1; j++) {
      for (long long c = j + 1; c < M; c++) {
        for (long long l = 1; l <= cnt[c]; l++) {
          dp[i + l][c] += f[l + i + 1] / f[i + 1] / f[l] * dp[i][j];
        }
      }
    }
  }
  if (fl && cnt[0] != 0) {
    cnt[0]--;
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < M; j++) {
        dp2[i][j] = 0;
      }
    }
    for (long long i = 0; i < M; i++) {
      for (long long j = 0; j < cnt[i]; j++) {
        dp2[j][i] = 1;
      }
    }
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < M - 1; j++) {
        for (long long c = j + 1; c < M; c++) {
          for (long long l = 1; l <= cnt[c]; l++) {
            dp2[i + l][c] += f[l + i + 1] / f[i + 1] / f[l] * dp2[i][j];
          }
        }
      }
    }
    cnt[0]++;
    for (long long i = 0; i < M; i++) {
      for (long long j = 0; j < M; j++) {
        dp[i + 1][j] -= dp2[i][j];
      }
    }
    dp[0][0] = 0;
  }
  long long ans = 0;
  for (long long i = 0; i < M; i++) {
    ans += dp[n - 1][i];
  }
  return ans;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  cin >> need >> t;
  for (long long i = 0; i < M; i++) {
    cnt[i] = t;
  }
  f[0] = 0;
  f[1] = 1;
  for (long long i = 2; i <= 20; i++) {
    f[i] = f[i - 1] * i;
  }
  solve(M, 1);
  long long s = 0, m;
  for (long long i = 0; i < M; i++) {
    long long f = 0;
    for (long long j = 0; j < M; j++) {
      s += dp[i][j];
      if (s >= need) {
        f = j;
        break;
      }
    }
    if (f) {
      m = i + 1;
      break;
    }
  }
  long long ans = 0;
  for (long long i = 0; i < m - 1; i++) {
    for (long long j = 0; j < M; j++) {
      ans += dp[i][j];
    }
  }
  vector<long long> v;
  for (long long i = 0; i < m; i++) {
    for (long long j = (i == 0); j < M; j++) {
      if (cnt[j] == 0) continue;
      cnt[j]--;
      long long c = solve(m - i - 1, 0);
      if (ans + c < need) {
        ans += c;
        cnt[j]++;
      } else {
        v.push_back(j);
        break;
      }
    }
  }
  for (auto to : v) {
    if (to < 10)
      cout << char(to + '0');
    else
      cout << char(to - 10 + 'a');
  }
}
