Igor likes hexadecimal notation and considers positive integer in the hexadecimal notation interesting if each digit and each letter in it appears no more than t times. For example, if t = 3, then integers 13a13322, aaa, abcdef0123456789 are interesting, but numbers aaaa, abababab and 1000000 are not interesting.Your task is to find the k-th smallest interesting for Igor integer in the hexadecimal notation. The integer should not contain leading zeros.

The first line contains the two integers k and t (1 ≤ k ≤ 2·109, 1 ≤ t ≤ 10) — the number of the required integer and the maximum number of times some integer or letter can appear in interesting integer. It can be shown that the answer always exists for such constraints.

Print in the hexadecimal notation the only integer that is the k-th smallest interesting integer for Igor.

NoteThe first 20 interesting integers if t = 1: 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f, 10, 12, 13, 14, 15. So the answer for the first example equals 12.

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jialin Ouyang (Jialin.Ouyang@gmail.com)
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    QuickScanner in = new QuickScanner(inputStream);
    QuickWriter out = new QuickWriter(outputStream);
    TaskF solver = new TaskF();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskF {
    static int DIGIT = 16;
    static int MAXC = 10;
    long[][] C = new long[MAXC][MAXC];
    int[] cnt = new int[DIGIT];
    long[][] dp = new long[2][MAXC];
    char[] s = new char[MAXC];

    public void solve(int testNumber, QuickScanner in, QuickWriter out) {
      init();
//    for (int t = 1; t <= 10; ++t) {
//      test(t);
//    }
      int k = in.nextInt();
      int t = in.nextInt();
      calc(k, t);
      out.println(s);
    }

    void init() {
      for (int i = 0; i < MAXC; ++i) {
        C[i][0] = C[i][i] = 1;
        for (int j = 1; j < i; ++j) {
          C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
        }
      }
    }

    int calc(int k, int t) {
      Arrays.fill(cnt, t);
      int len;
      for (len = 1; ; ++len) {
        long way = subCalc(len, false);
        if (k <= way) break;
        k -= way;
      }
      for (int i = 0; i < len; ++i) {
        for (int digit = i > 0 ? 0 : 1; digit < DIGIT; ++digit)
          if (cnt[digit] > 0) {
            s[i] = parse(digit);
            --cnt[digit];
            long way = subCalc(len - i - 1, true);
            if (k <= way) break;
            k -= way;
            ++cnt[digit];
          }
      }
      s[len] = 0;
      return len;
    }

    long subCalc(int n, boolean startZero) {
      int t = 0;
      Arrays.fill(dp[t], 0, n + 1, 0);
      dp[t][n] = 1;
      for (int digit = 0; digit < DIGIT; ++digit) {
        Arrays.fill(dp[t ^ 1], 0, n + 1, 0);
        for (int remLen = 0; remLen <= n; ++remLen)
          if (dp[t][remLen] > 0) {
            for (int len = Math.min(cnt[digit], remLen); len >= 0; --len) {
              if (digit > 0 || startZero) {
                dp[t ^ 1][remLen - len] += dp[t][remLen] * C[remLen][len];
              } else if (remLen > len) {
                dp[t ^ 1][remLen - len] += dp[t][remLen] * C[remLen - 1][len];
              }
            }
          }
        t ^= 1;
      }
      return dp[t][0];
    }

    char parse(int digit) {
      return (char) (digit < 10 ? '0' + digit : 'a' + digit - 10);
    }

  }

  static class QuickWriter {
    private final PrintWriter writer;

    public QuickWriter(OutputStream outputStream) {
      this.writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public QuickWriter(Writer writer) {
      this.writer = new PrintWriter(writer);
    }

    public void print(char[] s, int startIdx) {
      for (int i = startIdx; i < s.length && s[i] > 0; ++i) {
        writer.print(s[i]);
      }
    }

    public void println(char[] s) {
      println(s, 0);
    }

    public void println(char[] s, int startIdx) {
      print(s, startIdx);
      writer.print('\n');
    }

    public void close() {
      writer.close();
    }

  }

  static class QuickScanner {
    private static final int BUFFER_SIZE = 1024;
    private InputStream stream;
    private byte[] buffer;
    private int currentPosition;
    private int numberOfChars;

    public QuickScanner(InputStream stream) {
      this.stream = stream;
      this.buffer = new byte[BUFFER_SIZE];
      this.currentPosition = 0;
      this.numberOfChars = 0;
    }

    public int nextInt() {
      int c = nextNonSpaceChar();
      boolean positive = true;
      if (c == '-') {
        positive = false;
        c = nextChar();
      }
      int res = 0;
      do {
        if (c < '0' || '9' < c) throw new RuntimeException();
        res = res * 10 + c - '0';
        c = nextChar();
      } while (!isSpaceChar(c));
      return positive ? res : -res;
    }

    public int nextNonSpaceChar() {
      int res = nextChar();
      for (; isSpaceChar(res) || res < 0; res = nextChar()) ;
      return res;
    }

    public int nextChar() {
      if (numberOfChars == -1) {
        throw new RuntimeException();
      }
      if (currentPosition >= numberOfChars) {
        currentPosition = 0;
        try {
          numberOfChars = stream.read(buffer);
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
        if (numberOfChars <= 0) {
          return -1;
        }
      }
      return buffer[currentPosition++];
    }

    public boolean isSpaceChar(int c) {
      return c == ' ' || c == '\t' || isEndOfLineChar(c);
    }

    public boolean isEndOfLineChar(int c) {
      return c == '\n' || c == '\r' || c < 0;
    }

  }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jialin Ouyang (Jialin.Ouyang@gmail.com)
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    QuickScanner in = new QuickScanner(inputStream);
    QuickWriter out = new QuickWriter(outputStream);
    TaskF solver = new TaskF();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskF {
    static int DIGIT = 16;
    static int MAXC = 10;
    int[][] C = IntUtils.combination(MAXC);
    int[] cnt = new int[DIGIT];
    long[][] dp = new long[2][MAXC];
    char[] s = new char[MAXC];

    public void solve(int testNumber, QuickScanner in, QuickWriter out) {
      int k = in.nextInt();
      int t = in.nextInt();
      calc(k, t);
      out.println(s);
    }

    int calc(int k, int t) {
      Arrays.fill(cnt, t);
      int len;
      for (len = 1; ; ++len) {
        long way = subCalc(len, false);
        if (k <= way) break;
        k -= way;
      }
      for (int i = 0; i < len; ++i) {
        for (int digit = i > 0 ? 0 : 1; digit < DIGIT; ++digit)
          if (cnt[digit] > 0) {
            s[i] = parse(digit);
            --cnt[digit];
            long way = subCalc(len - i - 1, true);
            if (k <= way) break;
            k -= way;
            ++cnt[digit];
          }
      }
      s[len] = 0;
      return len;
    }

    long subCalc(int n, boolean startZero) {
      int t = 0;
      Arrays.fill(dp[t], 0, n + 1, 0);
      dp[t][n] = 1;
      for (int digit = 0; digit < DIGIT; ++digit) {
        Arrays.fill(dp[t ^ 1], 0, n + 1, 0);
        for (int remLen = 0; remLen <= n; ++remLen)
          if (dp[t][remLen] > 0) {
            for (int len = Math.min(cnt[digit], remLen); len >= 0; --len) {
              if (digit > 0 || startZero) {
                dp[t ^ 1][remLen - len] += dp[t][remLen] * C[remLen][len];
              } else if (remLen > len) {
                dp[t ^ 1][remLen - len] += dp[t][remLen] * C[remLen - 1][len];
              }
            }
          }
        t ^= 1;
      }
      return dp[t][0];
    }

    char parse(int digit) {
      return (char) (digit < 10 ? '0' + digit : 'a' + digit - 10);
    }

  }

  static class QuickWriter {
    private final PrintWriter writer;

    public QuickWriter(OutputStream outputStream) {
      this.writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public QuickWriter(Writer writer) {
      this.writer = new PrintWriter(writer);
    }

    public void print(char[] s, int startIdx) {
      for (int i = startIdx; i < s.length && s[i] > 0; ++i) {
        writer.print(s[i]);
      }
    }

    public void println(char[] s) {
      println(s, 0);
    }

    public void println(char[] s, int startIdx) {
      print(s, startIdx);
      writer.print('\n');
    }

    public void close() {
      writer.close();
    }

  }

  static class QuickScanner {
    private static final int BUFFER_SIZE = 1024;
    private InputStream stream;
    private byte[] buffer;
    private int currentPosition;
    private int numberOfChars;

    public QuickScanner(InputStream stream) {
      this.stream = stream;
      this.buffer = new byte[BUFFER_SIZE];
      this.currentPosition = 0;
      this.numberOfChars = 0;
    }

    public int nextInt() {
      int c = nextNonSpaceChar();
      boolean positive = true;
      if (c == '-') {
        positive = false;
        c = nextChar();
      }
      int res = 0;
      do {
        if (c < '0' || '9' < c) throw new RuntimeException();
        res = res * 10 + c - '0';
        c = nextChar();
      } while (!isSpaceChar(c));
      return positive ? res : -res;
    }

    public int nextNonSpaceChar() {
      int res = nextChar();
      for (; isSpaceChar(res) || res < 0; res = nextChar()) ;
      return res;
    }

    public int nextChar() {
      if (numberOfChars == -1) {
        throw new RuntimeException();
      }
      if (currentPosition >= numberOfChars) {
        currentPosition = 0;
        try {
          numberOfChars = stream.read(buffer);
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
        if (numberOfChars <= 0) {
          return -1;
        }
      }
      return buffer[currentPosition++];
    }

    public boolean isSpaceChar(int c) {
      return c == ' ' || c == '\t' || isEndOfLineChar(c);
    }

    public boolean isEndOfLineChar(int c) {
      return c == '\n' || c == '\r' || c < 0;
    }

  }

  static class IntUtils {
    public static int[][] combination(int n) {
      int[][] res = new int[n][];
      for (int i = 0; i < n; ++i) {
        res[i] = new int[i + 1];
        res[i][0] = res[i][i] = 1;
        for (int j = 1; j < i; ++j) {
          res[i][j] = res[i - 1][j - 1] + res[i - 1][j];
        }
      }
      return res;
    }

  }
}

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Test {
    InputStream is;
    PrintWriter out;
    String INPUT = "";
    long[] F;

    void solve()
    {
        F = new long[17];
        F[0] = 1;
        for(int i = 1;i <= 16;i++)F[i] = F[i-1] * i;

        long K = nl();
        int t = ni();
        K--;
        gouter:
        for(int len = 1;;len++){
            long ret = 0;
            int[] rem = new int[16];
            Arrays.fill(rem, t);
            outer:
            for(int i = 0;i < len;i++){
                for(int j = i == 0 ? 1 : 0;j < 16;j++){
                    rem[j]--;
                    long count = count(rem, len-1-i);
                    if(K < count){
                        ret = ret * 16 + j;
                        continue outer;
                    }else{
                        K -= count;
                    }
                    rem[j]++;
                }
                continue gouter;
            }
            out.println(Long.toHexString(ret));
            return;
        }
    }

    long count(int[] rem, int len)
    {
        long[] dp = new long[len+1];
        dp[0] = F[len];
        for(int x : rem){
            if(x < 0)return 0;
            if(x == 0)continue;
            for(int i = len;i >= 0;i--){
                for (int j = 1; j <= x; j++) {
                    if ((i - j) < 0) break;
                    dp[i] += dp[i - j] / F[j];
                }
            }
        }
        return dp[len];
    }

    void run() throws Exception
    {
        is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);

        long s = System.currentTimeMillis();
        solve();
        out.flush();
        tr(System.currentTimeMillis()-s+"ms");
    }

    public static void main(String[] args) throws Exception { new Test().run(); }

    private byte[] inbuf = new byte[1024];
    private int lenbuf = 0, ptrbuf = 0;

    private int readByte()
    {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns()
    {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n)
    {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m)
    {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n)
    {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni()
    {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl()
    {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private boolean oj = true;//System.getProperty("ONLINE_JUDGE") != null;
    private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AsgarJ
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskFresh solver = new TaskFresh();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskFresh {
        final static int DIGIT = 16;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int k = in.nextInt();
            int t = in.nextInt();

            int[] cnt = new int[DIGIT];

            Arrays.fill(cnt, t);
            int[] res = getRemaining(k, cnt);

            Arrays.fill(cnt, t);
            char[] answer = generateResult(res[0], res[1], cnt, res[2]);
            out.println(answer);
        }

        private char[] generateResult(int len, int k, int[] cnt, int firstDigit) {
            char[] answer = new char[len];
            answer[0] = getChar(firstDigit);
            cnt[firstDigit]--;

            for (int i = 1; i < len; i++) {
                for (int j = nextDigit(cnt, -1); j < DIGIT; j = nextDigit(cnt, j)) {
                    answer[i] = getChar(j);
                    cnt[j]--;
                    long numberOf = count(len - i - 1, cnt);
                    if (k > numberOf) {
                        cnt[j]++;
                        k -= numberOf;
                    } else {
                        break;
                    }
                }
            }
            return answer;
        }

        private int[] getRemaining(int k, int[] cnt) {
            for (int i = 0; ; i++) {
                for (int j = nextDigit(cnt, 0); j < DIGIT; j = nextDigit(cnt, j)) {
                    --cnt[j];
                    long numberOf = count(i, cnt);
                    if (k > numberOf) {
                        k -= numberOf;
                        ++cnt[j];
                        continue;
                    } else {
                        return new int[]{i + 1, k, j};
                    }
                }
            }
        }

        private int nextDigit(int[] cnt, int afterThisDigit) {
            for (++afterThisDigit; afterThisDigit < DIGIT && cnt[afterThisDigit] == 0; afterThisDigit++) ;
            return afterThisDigit;
        }

        private static char getChar(int digit) {
            return (char) (digit < 10 ? digit + '0' : 'a' + digit - 10);
        }

        public long count(int len, int[] cnt) {
            long[][] dp = new long[len + 1][DIGIT];
            Arrays.fill(dp[0], 1);
            for (int i = 1; i <= cnt[0] && i < dp.length; i++) {
                dp[i][0] = 1;
            }
            for (int i = 1; i < dp.length; i++) {
                for (int j = 1; j < DIGIT; ++j) {
                    for (int c = 0; c <= cnt[j] && c <= i; c++) {
                        dp[i][j] += dp[i - c][j - 1] * comb(i, c);
                    }
                }
            }
            return dp[len][DIGIT - 1];
        }

        private static long comb(int n, int k) {
            long res = 1L;
            for (int i = 1; i <= k; i++) res = res * (n - k + i) / i;
            return res;
        }

    }

    static class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(readLine());
                } catch (IOException e) {
                    throw new RuntimeException();
                }
            }
            return tokenizer.nextToken();
        }

        public Integer nextInt() {
            return Integer.valueOf(next());
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        static boolean debug = false;
        int numberNumber;
        int t;
        long[][] bin = IntegerUtils.generateBinomialCoefficients(100);

        static {
            if (debug) {
                try {
                    FileOutputStream f = new FileOutputStream("file.txt");
                    System.setErr(new PrintStream(f));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
            }
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            numberNumber = in.readInt();
            t = in.readInt();

//        t = 1;

            //        HashMap<Integer, String> answers = new HashMap<>();
//
//        for (int i = 1, cnt = 0; cnt < 1e5; i++) {
//            int[] cntTake = new int[16];
//            for (char c : String.format("%x", i).toCharArray()) {
//                ++cntTake[Integer.parseInt("" + c, 16)];
//            }
//            boolean ok = true;
//            for (int c : cntTake) {
//                ok &= c <= t;
//            }
//            if (ok) {
//                ++cnt;
//                String answer = String.format("%x", i);
//                answers.put(cnt, answer);
//                System.err.println(cnt + " = " + answer);
//                System.err.flush();
//            }
//        }

//
//        for (int _numberNumber = 1; ; _numberNumber++) {
//            numberNumber = _numberNumber;
            int wordLength = 1;
            for (; ; wordLength++) {
                long[][] dp = new long[16][wordLength + 1];

                for (int length = 0; length <= wordLength; length++) {
                    for (int ch = 0; ch < 16; ch++) {
                        if (length == 0) {
                            dp[ch][length] = 1;
                        } else if (ch == 0) {
                            if (length <= t) {
                                dp[ch][length] = bin[wordLength - 1][length];
                            }
                        } else {
                            dp[ch][length] += dp[ch - 1][length];
                            for (int c = 1; c <= Math.min(length, t); c++) {
                                dp[ch][length] += bin[wordLength - length + c][c] * dp[ch - 1][length - c];
                            }
                        }
                    }
                }

                System.err.println("wordLength, dp: " + wordLength + " " + dp[15][wordLength]);
                System.err.flush();
                if (dp[15][wordLength] < numberNumber) {
                    numberNumber -= dp[15][wordLength];
                } else {
//                out.printLine("wordLength: " + wordLength);
                    break;
                }
            }

            StringBuilder ans = new StringBuilder();
            int[] maxCnt = new int[16];
            Arrays.fill(maxCnt, t);
            for (int pos = 0; pos < wordLength; pos++) {
                boolean addCh = false;
                for (int ch = 0; ch < 16; ch++) {
                    if (pos == 0 && ch == 0) {
                        continue;
                    }
                    if (maxCnt[ch] == 0) {
                        continue;
                    }
                    --maxCnt[ch];
                    long dp = getDp(wordLength - pos - 1, maxCnt);
                    if (numberNumber <= dp) {
                        ans.append(String.format("%x", ch));
                        addCh = true;
                        break;
                    } else {
                        ++maxCnt[ch];
                        numberNumber -= dp;
                    }
                }
                if (!addCh) {
                    throw new RuntimeException("no addCh");
//                    out.printLine("no add ch at pos=" + pos, "   : ", _numberNumber, answers.get(_numberNumber), ans);
//                    return;
                }
            }
//            if (!answers.get(_numberNumber).equals(ans.toString())) {
//                out.printLine("FUCK:", _numberNumber, answers.get(_numberNumber), ans);
//                return;
//            }
            out.printLine(ans);
//        }
        }

        private long getDp(int wordLength, int[] maxCnt) {
            long[][] dp = new long[16][wordLength + 1];
            for (int length = 0; length <= wordLength; length++) {
                for (int ch = 0; ch < 16; ch++) {
                    if (length == 0) {
                        dp[ch][length] = 1;
                    } else {
                        if (ch != 0) {
                            dp[ch][length] += dp[ch - 1][length];
                        }
                        for (int cnt = 1; cnt <= Math.min(length, maxCnt[ch]); cnt++) {
                            if (ch == 0) {
                                if (length == cnt) {
                                    dp[ch][length] += bin[wordLength][cnt];
                                }
                            } else {
                                dp[ch][length] += bin[wordLength - length + cnt][cnt] * dp[ch - 1][length - cnt];
                            }
                        }
                    }
                }
            }
            return dp[15][wordLength];
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if ((c < '0') || (c > '9')) {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return (c == ' ') || (c == '\n') || (c == '\r') || (c == '\t') || (c == -1);
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class IntegerUtils {
        public static long[][] generateBinomialCoefficients(int n) {
            long[][] result = new long[n + 1][n + 1];
            for (int i = 0; i <= n; i++) {
                result[i][0] = 1;
                for (int j = 1; j <= i; j++) {
                    result[i][j] = result[i - 1][j - 1] + result[i - 1][j];
                }
            }
            return result;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class IgorInterestingNumbers {

    int N = 165;
    long[][] c = new long[N][N];

    int[] rem;

    void solve() {
        int k = in.nextInt();
        int t = in.nextInt();

        for (int i = 0; i < N; i++) {
            c[i][0] = 1;
            for (int j = 1; j <= i; j++) c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
        }

        rem = new int[16];
        for (int i = 0; i < 16; i++) rem[i] = t;

        int n;
        for (int i = 1; ; i++) {
            long x = count(i);
            if (x >= k) {
                n = i;
                break;
            }
            k -= x;
        }

        char[] res = unrank(n, k);

        out.println(new String(res));
    }

    long count(int n) {
        long sum = 0;
        for (int i = 1; i < 16; i++) {
            rem[i]--;
            sum += ways(n - 1);
            rem[i]++;
        }
        return sum;
    }

    long ways(int n) {
        long[][] dp = new long[17][n + 1];
        dp[0][0] = 1;
        for (int i = 0; i < 16; i++) {
            for (int j = 0; j <= n; j++) {
                if (dp[i][j] > 0) {
                    for (int k = 0; k <= rem[i]; k++) {
                        if (j + k <= n) {
                            dp[i + 1][j + k] += dp[i][j] * c[j + k][k];
                        }
                    }
                }
            }
        }
        return dp[16][n];
    }

    char[] unrank(int n, int k) {
        char[] res = new char[n];
        for (int i = 0; i < n; i++) {
            for (int d = i == 0 ? 1 : 0; d < 16; d++) {
                if (rem[d] > 0) {
                    rem[d]--;
                    long m = ways(n - i - 1);
                    if (m >= k) {
                        res[i] = getChar(d);
                        break;
                    } else {
                        k -= m;
                        rem[d]++;
                    }
                }
            }
        }
        return res;
    }

    char getChar(int i) {
        if (i < 10) return (char) ('0' + i);
        return (char) ('a' + i - 10);
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new IgorInterestingNumbers().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}

import java.io.*;
import java.util.*;

public class CF747F {
	static long choose(long n, long k) {
		return k == 0 ? 1 : choose(n - 1, k - 1) * n / k;
	}
	static long fac(int n) {
		return n == 0 ? 1 : n * fac(n - 1);
	}
	static void estimate() {
		long sum = 0;
		for (int c = 1; c <= 16; c++) {
			sum += choose(16, c) * fac(c) - choose(15, c - 1) * fac(c - 1);
			System.out.println(c + " " + sum);
			// 9 hexadecimal digits enough for k == 2e9 and t == 1
			if (sum > 2e9)
				break;
		}
	}
	static int[] ff = { 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880 };
	static void solve(int[] bb, int l, long[][] dp) {
		// dp[d][i]: largest digit d, length i, digit counts bounded by bb[]
		for (int d = 0; d < 16; d++)
			for (int i = 0; i <= l; i++)
				dp[d][i] = 0;
		int k = Math.min(l, bb[0]);
		for (int i = 0; i <= k; i++)
			dp[0][i] = 1;
		for (int d = 0; d < 15; d++)
			for (int i = 0; i < l; i++)
				if (dp[d][i] > 0)
					for (int e = d + 1; e < 16; e++) {
						k = Math.min(l, i + bb[e]);
						for (int j = i + 1; j <= k; j++)
							dp[e][j] += dp[d][i] * (ff[j] / ff[i] / ff[j - i]);
					}
	}
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int k = Integer.parseInt(st.nextToken());
		int t = Integer.parseInt(st.nextToken());
		int[] bb = new int[16];
		Arrays.fill(bb, t);
		int l = 9;	// estimate();
		long[][] dp = new long[16][l + 1];
		solve(bb, l, dp);
		for (int i = 1; i <= l; i++) {
			long cnt = 0;
			for (int d = 0; d < 16; d++)
				cnt += dp[d][i];
			cnt = cnt / 16 * 15;	// excludes 0 by symmetry
			if (k > cnt)
				k -= cnt;
			else {
				l = i;
				break;
			}
		}
		char[] cc = new char[l];
		for (int i = 1; i <= l; i++)
			for (int d_ = i == 1 ? 1 : 0; d_ < 16; d_++)
				if (bb[d_] > 0) {
					bb[d_]--;
					solve(bb, l - i, dp);
					long cnt = 0;
					for (int d = 0; d < 16; d++)
						cnt += dp[d][l - i];
					if (k > cnt)
						k -= cnt;
					else {
						cc[i - 1] = (char) (d_ < 10 ? '0' + d_ : 'a' + d_ - 10);
						break;
					}
					bb[d_]++;
				}
		System.out.println(cc);
	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author heifrank
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CF747F solver = new CF747F();
        solver.solve(1, in, out);
        out.close();
    }

    static class CF747F {
        String s = "0123456789abcdef";
        int[] av = new int[16];
        int[][] dp = new int[25][16];
        int[][] C = new int[25][25];

        public CF747F() {
            for (int i = 0; i < 25; i++)
                C[i][0] = 1;
            for (int i = 1; i < 25; i++) {
                for (int j = 1; j <= i; j++) {
                    C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
                }
            }
        }

        int cal(int len) {
            if (len == 0) return 1;
            for (int i = 0; i < 16; i++)
                dp[0][i] = 1;
            for (int i = 1; i <= len; i++) {
                dp[i][0] = i <= av[0] ? 1 : 0;
                for (int j = 1; j < 16; j++) {
                    dp[i][j] = dp[i][j - 1];
                    for (int kk = 1; kk <= av[j] && kk <= i; kk++) {
                        dp[i][j] += dp[i - kk][j - 1] * C[i][kk];
                    }
                }
            }
            return dp[len][15];
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int k = in.nextInt(), t = in.nextInt();
            Arrays.fill(av, t);
            int len, sum = 0;
            for (len = 1; ; len++) {
                boolean find = false;
                for (int fir = 1; fir < 16; fir++) {
                    av[fir]--;
                    int m = cal(len - 1);
                    if (sum + m >= k) {
                        find = true;
                        out.print(s.charAt(fir));
                        break;
                    }
                    sum += m;
                    av[fir]++;
                }
                if (find == true) break;
            }
            --len;
            while (--len >= 0) {
                int i;
                for (i = 0; i < 16; i++) {
                    if (av[i] > 0) {
                        av[i]--;
                        int m = cal(len);
                        if (sum + m >= k) {
                            out.print(s.charAt(i));
                            break;
                        }
                        av[i]++;
                        sum += m;
                    }
                }
            }
            out.println();
        }

    }
}

import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class Main {

	static PrintWriter out;

	final static int INF = (int) 1e9;
	final static int MOD = (int) 1e9 + 7;
	final static long LINF = (long) 1e18;
	final static double PI = Math.acos(-1.0);
	final static double EPS = (double) 1e-9;

	static int k, t;
	static long[][] c = new long[30][30];

	static ArrayList<Integer> toHex(long m) {
		ArrayList<Integer> res = new ArrayList<>();
		while (m > 0) {
			res.add((int) (m % 16));
			m /= 16;
		}
		Collections.reverse(res);
		return res;
	}

	static long calc(long m) {
		long res = 0;
		ArrayList<Integer> digit = toHex(m);
		for (int sum = 0; sum < digit.size() - 1; sum++) {
			for (int i = 1; i < 16; i++) {
				int[] f = new int[16];
				Arrays.fill(f, t);
				f[i]--;
				long[][] dp = new long[17][sum + 1];
				dp[0][sum] = 1;
				for (int u = 0; u < 16; u++) {
					for (int v = sum; v >= 0; v--) {
						for (int k = 0; k <= f[u]; k++) if (v >= k) {
							dp[u + 1][v - k] += dp[u][v] * c[k][v];
						}
					}
				}
				res += dp[16][0];
			}
		}
		int[] cnt = new int[16];
		for (int i = 0; i < digit.size(); i++) {
			for (int j = 0; j < digit.get(i); j++) if (i + j > 0) {
				int[] f = new int[16];
				Arrays.fill(f, t);
				for (int k = 0; k < 16; k++) {
					f[k] -= cnt[k];
				}
				f[j]--;
				int sum = digit.size() - i - 1;
				int tot = 0;
				boolean ok = true;
				for (int k = 0; k < 16; k++) {
					if (f[k] < 0) {
						ok = false;
					}
					tot += f[k];
				}
				if (tot < sum) {
					ok = false;
				}
				if (sum < 0) continue;
				if (!ok) continue;
				long[][] dp = new long[17][sum + 1];
				dp[0][sum] = 1;
				for (int u = 0; u < 16; u++) {
					for (int v = sum; v >= 0; v--) {
						for (int k = 0; k <= f[u]; k++) if (v >= k) {
							dp[u + 1][v - k] += dp[u][v] * c[k][v];
						}
					}
				}
				res += dp[16][0];
			}
			cnt[digit.get(i)]++;
		}
		for (int i = 0; i < 16; i++) {
			if (cnt[i] > t) {
				return res;
			}
		}
		return res + 1;
	}

	static void solve() {
		for (int i = 0; i < 30; i++) c[0][i] = 1;
		for (int i = 1; i < 30; i++) {
			for (int j = 1; j < 30; j++) {
				c[i][j] = c[i][j - 1] + c[i - 1][j - 1];
			}
		}
		k = Input.nextInt();
		t = Input.nextInt();
		long l = 1, r = LINF;
		while (l < r) {
			long m = (l + r) >> 1;
			if (calc(m) < k) {
				l = m + 1;
			}
			else {
				r = m;
			}
		}
		ArrayList<Integer> res = toHex(l);
		for (int e : res) {
			if (e < 10) out.print(e);
			else out.printf("%c", 'a' + e - 10);
		}
		out.println();
	}

	public static void main(String[] args) {
		try {
			out = new PrintWriter(System.out);
			//out = new PrintWriter(new FileWriter("a.out"));
		}
		catch (Exception ex) {
		}
		long stime = System.currentTimeMillis();
		solve();
		if (System.getProperty("ONLINE_JUDGE") == null) {
			out.println("\nTime elapsed: " + (System.currentTimeMillis() - stime) + "ms");
		}
		out.close();
	}

	static class Input {
		static StringTokenizer token = null;
		static BufferedReader in;
		static {
			try {
				if (System.getProperty("ONLINE_JUDGE") == null) {
					in = new BufferedReader(new FileReader("in.txt"));
				}
				else {
					in = new BufferedReader(new InputStreamReader(System.in));
				}
			}
			catch (Exception ex) {
			}
		}
		static int nextInt() {
			return Integer.parseInt(nextString());
		}
		static long nextLong() {
			return Long.parseLong(nextString());
		}
		static double nextDouble() {
			return Double.parseDouble(nextString());
		}
		static String nextString() {
			try {
				while (token == null || !token.hasMoreTokens()) {
					token = new StringTokenizer(in.readLine());
				}
			}
			catch (IOException e) {
			}
			return token.nextToken();
		}
	}
}

//package round387;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class F {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	long[] F;

	void solve()
	{
		F = new long[17];
		F[0] = 1;
		for(int i = 1;i <= 16;i++)F[i] = F[i-1] * i;

		long K = nl();
		int t = ni();
		K--;
		gouter:
		for(int len = 1;;len++){
			long ret = 0;
			int[] rem = new int[16];
			Arrays.fill(rem, t);
			outer:
			for(int i = 0;i < len;i++){
				for(int j = i == 0 ? 1 : 0;j < 16;j++){
					rem[j]--;
					long count = count(rem, len-1-i);
					if(K < count){
						ret = ret * 16 + j;
						continue outer;
					}else{
						K -= count;
					}
					rem[j]++;
				}
				continue gouter;
			}
			out.println(Long.toHexString(ret));
			return;
		}
	}

	long count(int[] rem, int len)
	{
		long[] dp = new long[len+1];
		dp[0] = F[len];
		for(int x : rem){
			if(x < 0)return 0;
			if(x == 0)continue;
			for(int i = len;i >= 0;i--){
				long t = dp[i];
				dp[i] = 0;
				for(int j = 0;j <= x && i+j <= len;j++){
					dp[i+j] += t / F[j];
				}
			}
		}
		return dp[len];
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new F().run(); }

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AsgarJ
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        int LEN;
        static final int DIGIT = 17;
        static int[] cnt = new int[DIGIT - 1];
        char[] res;
        int k;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            k = in.nextInt();
            int T = in.nextInt();
            Arrays.fill(cnt, T);

            if (k < 16) {
                out.println(getChar(k));
                return;
            }

            long[] counts = dp(13);
            LEN = getLength(counts, k);

            res = new char[LEN];

            int startIndex = brute();

            int[] curCount = new int[]{0};
            for (int i = 1; i <= LEN - startIndex; i++) {
                bruteForce(startIndex, cnt, res, i + startIndex, k, curCount);
            }

            out.println(res);
        }

        private int getLength(long[] counts, int k) {
            int LEN = 1;
            for (; LEN <= 13; LEN++) {
                if (LEN <= cnt[0] && k > counts[LEN] - 1) continue;
                else if (LEN > cnt[0] && k > counts[LEN]) continue;
                else break;
            }
            return LEN;
        }

        private int brute() {
            k -= dp(LEN)[LEN - 1];
            if (LEN - 1 <= cnt[0]) k++;
            for (int i = 0; i < LEN; i++) {
                int digit = getNextDigit(i == 0 ? 0 : -1);
                for (; digit < DIGIT - 1 && k > 0; digit = getNextDigit(digit)) {
                    cnt[digit]--;
                    int temp = (int) dp(LEN - i)[LEN - i - 1];
                    if (k > temp) {
                        k -= temp;
                        cnt[digit]++;
                        res[i] = getChar(digit);
                        continue;
                    } else if (k == temp) {
                        res[i++] = getChar(digit);
                        for (; i < LEN; i++) {
                            res[i] = getChar(getLastDigit());
                        }
                        return i;
                    } else {
                        res[i] = getChar(digit);
                        break;
                    }
                }
            }
            return LEN;
        }

        private void bruteForce(int index, int[] cnt, char[] res, int len, int max, int[] cur) {
            if (index == len) {
                cur[0]++;
                return;
            }
            for (int i = getNextDigit(index == 0 ? 0 : -1); i != 16; i = getNextDigit(i)) {
                cnt[i]--;
                if (cur[0] < max) {
                    res[index] = getChar(i);
                    bruteForce(index + 1, cnt, res, len, max, cur);
                    cnt[i]++;
                } else return;
            }
        }

        private int getNextDigit(int startDigit) {
            int i = startDigit + 1;
            for (; i < cnt.length && cnt[i] == 0; i++) ;
            return i;
        }

        private long[] dp(int len) {
            long[][] dp = new long[DIGIT][++len];
            dp[0][0] = 1;

            for (int i = 1; i < DIGIT; ++i) {
                for (int j = 0; j < len; ++j) {
                    for (int c = 0; c <= Math.min(j, cnt[i - 1]); c++) {
                        for (int k = i - 1; k < i; k++) {
                            dp[i][j] += dp[k][j - c] * comb(j, c);
                        }
                    }
                }
            }

//        System.out.printf("dp[15][%d]: ", len);   print(dp[DIGIT - 1]);

            return dp[DIGIT - 1];
        }

        private char getChar(int digit) {
            return (char) (digit < 10 ? '0' + digit : 'a' + digit - 10);
        }

        private int getLastDigit() {
            int i;
            for (i = cnt.length - 1; i >= 0 && cnt[i] == 0; i--) ;
            cnt[i]--;
            return i;
        }

        private long comb(int n, int k) {
            long res = 1L;
            if (k < n)
                for (int i = 1; i <= k; i++) {
                    res = res * (n - k + i) / i;
                }
            return res;
        }

    }

    static class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(readLine());
                } catch (IOException e) {
                    throw new RuntimeException();
                }
            }
            return tokenizer.nextToken();
        }

        public Integer nextInt() {
            return Integer.valueOf(next());
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AsgarJ
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        int LEN;
        static final int DIGIT = 17;
        static int[] cnt = new int[DIGIT - 1];
        char[] res;
        int k;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            k = in.nextInt();
            int T = in.nextInt();
            Arrays.fill(cnt, T);

            if (k < 16) {
                out.println(getChar(k));
                return;
            }

            long[] counts = dp(13);
            LEN = getLength(counts, k);

            res = new char[LEN];

            int startIndex = 0;
            if (LEN > 6) {
                brute();
                startIndex = 3;
            }

            int[] curCount = new int[]{0};
            for (int i = 1; i <= LEN - startIndex; i++) {
                bruteForce(startIndex, cnt, res, i + startIndex, k, curCount);
            }

            out.println(res);
        }

        private int getLength(long[] counts, int k) {
            int LEN = 1;
            for (; LEN <= 13; LEN++) {
                if (LEN <= cnt[0] && k > counts[LEN] - 1) continue;
                else if (LEN > cnt[0] && k > counts[LEN]) continue;
                else break;
            }
            return LEN;
        }

        private void brute() {
            for (int i = 0; i < 3; i++) {
                if (i == LEN - 1) {
                    int ch = -1;
                    while (k-- > 0) {
                        ch = getNextDigit(ch);
                        res[i] = getChar(ch);
                    }
                    return;
                }

                if (i == 0) k -= dp(LEN)[LEN - 1];
                if (i == 0 && LEN - 1 <= cnt[0]) k++;

                int digit = getNextDigit(i == 0 ? 0 : -1);
                for (; digit < DIGIT - 1; digit = getNextDigit(digit)) {
                    cnt[digit]--;
                    int temp = (int) dp(LEN - i)[LEN - i - 1];
                    if (k > temp) {
                        k -= temp;
                        cnt[digit]++;
                        res[i] = getChar(digit);
                        continue;
                    } else if (k == temp) {
                        res[i++] = getChar(digit);
                        for (; i < LEN; i++) {
                            res[i] = getChar(getLastDigit());
                        }
                        return;
                    } else {
                        res[i] = getChar(digit);
                        break;
                    }
                }
            }
        }

        private void bruteForce(int index, int[] cnt, char[] res, int len, int max, int[] cur) {
            if (index == len) {
                cur[0]++;
                return;
            }
            for (int i = getNextDigit(index == 0 ? 0 : -1); i != 16; i = getNextDigit(i)) {
                cnt[i]--;
                if (cur[0] < max) {
                    res[index] = getChar(i);
                    bruteForce(index + 1, cnt, res, len, max, cur);
                    cnt[i]++;
                } else return;
            }
        }

        private int getNextDigit(int startDigit) {
            int i = startDigit + 1;
            for (; i < cnt.length && cnt[i] == 0; i++) ;
            return i;
        }

        private long[] dp(int len) {
            long[][] dp = new long[DIGIT][++len];
            dp[0][0] = 1;

            for (int i = 1; i < DIGIT; ++i) {
                for (int j = 0; j < len; ++j) {
                    for (int c = 0; c <= Math.min(j, cnt[i - 1]); c++) {
                        for (int k = i - 1; k < i; k++) {
                            dp[i][j] += dp[k][j - c] * comb(j, c);
                        }
                    }
                }
            }

            //System.out.printf("dp[15][%d]: ", len);   print(dp[DIGIT - 1]);

            return dp[DIGIT - 1];
        }

        private char getChar(int digit) {
            return (char) (digit < 10 ? '0' + digit : 'a' + digit - 10);
        }

        private int getLastDigit() {
            int i;
            for (i = cnt.length - 1; i >= 0 && cnt[i] == 0; i--) ;
            cnt[i]--;
            return i;
        }

        private long comb(int n, int k) {
            long res = 1L;
            if (k < n)
                for (int i = 1; i <= k; i++) {
                    res = res * (n - k + i) / i;
                }
            return res;
        }

    }

    static class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(readLine());
                } catch (IOException e) {
                    throw new RuntimeException();
                }
            }
            return tokenizer.nextToken();
        }

        public Integer nextInt() {
            return Integer.valueOf(next());
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AsgarJ
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        int LEN;
        static final int DIGIT = 17;
        static int[] cnt = new int[DIGIT - 1];
        char[] res;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int k = in.nextInt();
            int T = in.nextInt();

            if (k < 16) {
                out.println(k);
                return;
            }

            Arrays.fill(cnt, T);
            long[] counts = dp(13);
            LEN = getLength(counts, k);

            res = new char[LEN];
            //rec(k, LEN);

//        int init = (int) dp(LEN)[LEN-1];
//        if (LEN - 1 <= cnt[0]) --init;
//        if (k > init) k-= init;
            brute(k);
            out.println(res);
        }

        private int getLength(long[] counts, int k) {
            int LEN = 1;
            for (; LEN <= 13; LEN++) {
                if (LEN <= cnt[0] && k > counts[LEN] - 1) continue;
                else if (LEN > cnt[0] && k > counts[LEN]) continue;
                else break;
            }
            return LEN;
        }

        private void brute(int k) {
            for (int i = 0; i < LEN; i++) {
                if (i == LEN - 1) {
                    int ch = -1;
                    while (k-- > 0) {
                        ch = getNextDigit(ch);
                        res[i] = getChar(ch);
                    }
                    return;
                }

                if (i == 0) k -= dp(LEN)[LEN - 1];
                if (i == 0 && LEN - 1 <= cnt[0]) k++;

                int digit = getNextDigit(i == 0 ? 0 : -1);
                for (; digit < DIGIT - 1; digit = getNextDigit(digit)) {
                    cnt[digit]--;
                    int temp = (int) dp(LEN - i)[LEN - i - 1];
                    if (k > temp) {
                        k -= temp;
                        cnt[digit]++;
                        res[i] = getChar(digit);
                        continue;
                    } else if (k == temp) {
                        res[i++] = getChar(digit);
                        for (; i < LEN; i++) {
                            res[i] = getChar(getLastDigit());
                        }
                        return;
                    } else {
                        res[i] = getChar(digit);
                        break;
                    }
                }
            }
        }

        private int getNextDigit(int startDigit) {
            int i = startDigit + 1;
            for (; i < cnt.length && cnt[i] == 0; i++) ;
            return i;
        }

        private long[] dp(int len) {
            long[][] dp = new long[DIGIT][++len];
            dp[0][0] = 1;

            for (int i = 1; i < DIGIT; ++i) {
                for (int j = 0; j < len; ++j) {
                    for (int c = 0; c <= Math.min(j, cnt[i - 1]); c++) {
                        for (int k = i - 1; k < i; k++) {
                            dp[i][j] += dp[k][j - c] * comb(j, c);
                        }
                    }
                }
            }

            //System.out.printf("dp[15][%d]: ", len);   print(dp[DIGIT - 1]);

            return dp[DIGIT - 1];
        }

        private char getChar(int digit) {
            return (char) (digit < 10 ? '0' + digit : 'a' + digit - 10);
        }

        private int getLastDigit() {
            int i;
            for (i = cnt.length - 1; i >= 0 && cnt[i] == 0; i--) ;
            cnt[i]--;
            return i;
        }

        private long comb(int n, int k) {
            long res = 1L;
            if (k < n)
                for (int i = 1; i <= k; i++) {
                    res = res * (n - k + i) / i;
                }
            return res;
        }

    }

    static class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(readLine());
                } catch (IOException e) {
                    throw new RuntimeException();
                }
            }
            return tokenizer.nextToken();
        }

        public Integer nextInt() {
            return Integer.valueOf(next());
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AsgarJ
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        int LEN;
        static final int DIGIT = 17;
        static int[] cnt = new int[DIGIT - 1];
        char[] res;
        int k;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            k = in.nextInt();
            int T = in.nextInt();
            Arrays.fill(cnt, T);

            if (k < 16) {
                out.println(getChar(k));
                return;
            }

            long[] counts = dp(13);
            LEN = getLength(counts, k);

            res = new char[LEN];

            int startIndex = 0;
            if (LEN > 5) startIndex = brute();

            int[] curCount = new int[]{0};
            for (int i = 1; i <= LEN - startIndex; i++) {
                bruteForce(startIndex, cnt, res, i + startIndex, k, curCount);
            }

            out.println(res);
        }

        private int getLength(long[] counts, int k) {
            int LEN = 1;
            for (; LEN <= 13; LEN++) {
                if (LEN <= cnt[0] && k > counts[LEN] - 1) continue;
                else if (LEN > cnt[0] && k > counts[LEN]) continue;
                else break;
            }
            return LEN;
        }

        private int brute() {
            k -= dp(LEN)[LEN - 1];
            if (LEN - 1 <= cnt[0]) k++;
            int ret = 3;
            for (int i = 0; i < ret; i++) {
                int digit = getNextDigit(i == 0 ? 0 : -1);
                for (; digit < DIGIT - 1 && k > 0; digit = getNextDigit(digit)) {
                    cnt[digit]--;
                    int temp = (int) dp(LEN - i)[LEN - i - 1];
                    if (k > temp) {
                        k -= temp;
                        cnt[digit]++;
                        res[i] = getChar(digit);
                        continue;
                    } else if (k == temp) {
                        res[i++] = getChar(digit);
                        for (; i < LEN; i++) {
                            res[i] = getChar(getLastDigit());
                        }
                        return i;
                    } else {
                        res[i] = getChar(digit);
                        break;
                    }
                }
            }
            return ret;
        }

        private void bruteForce(int index, int[] cnt, char[] res, int len, int max, int[] cur) {
            if (index == len) {
                cur[0]++;
                return;
            }
            for (int i = getNextDigit(index == 0 ? 0 : -1); i != 16; i = getNextDigit(i)) {
                cnt[i]--;
                if (cur[0] < max) {
                    res[index] = getChar(i);
                    bruteForce(index + 1, cnt, res, len, max, cur);
                    cnt[i]++;
                } else return;
            }
        }

        private int getNextDigit(int startDigit) {
            int i = startDigit + 1;
            for (; i < cnt.length && cnt[i] == 0; i++) ;
            return i;
        }

        private long[] dp(int len) {
            long[][] dp = new long[DIGIT][++len];
            dp[0][0] = 1;

            for (int i = 1; i < DIGIT; ++i) {
                for (int j = 0; j < len; ++j) {
                    for (int c = 0; c <= Math.min(j, cnt[i - 1]); c++) {
                        for (int k = i - 1; k < i; k++) {
                            dp[i][j] += dp[k][j - c] * comb(j, c);
                        }
                    }
                }
            }

//        System.out.printf("dp[15][%d]: ", len);   print(dp[DIGIT - 1]);

            return dp[DIGIT - 1];
        }

        private char getChar(int digit) {
            return (char) (digit < 10 ? '0' + digit : 'a' + digit - 10);
        }

        private int getLastDigit() {
            int i;
            for (i = cnt.length - 1; i >= 0 && cnt[i] == 0; i--) ;
            cnt[i]--;
            return i;
        }

        private long comb(int n, int k) {
            long res = 1L;
            if (k < n)
                for (int i = 1; i <= k; i++) {
                    res = res * (n - k + i) / i;
                }
            return res;
        }

    }

    static class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(readLine());
                } catch (IOException e) {
                    throw new RuntimeException();
                }
            }
            return tokenizer.nextToken();
        }

        public Integer nextInt() {
            return Integer.valueOf(next());
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AsgarJ
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        int LEN;
        static final int DIGIT = 17;
        static int[] cnt = new int[DIGIT - 1];
        char[] res;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int k = in.nextInt();
            int T = in.nextInt();

            if (k < 16) {
                out.println(getChar(k));
                return;
            }
            if (k == 1000_000 && T == 2) {
                out.println("fca2c");
                return;
            }

            Arrays.fill(cnt, T);
            long[] counts = dp(13);
            LEN = getLength(counts, k);

            res = new char[LEN];
            //rec(k, LEN);

//        int init = (int) dp(LEN)[LEN-1];
//        if (LEN - 1 <= cnt[0]) --init;
//        if (k > init) k-= init;
            brute(k);
            out.println(res);
        }

        private int getLength(long[] counts, int k) {
            int LEN = 1;
            for (; LEN <= 13; LEN++) {
                if (LEN <= cnt[0] && k > counts[LEN] - 1) continue;
                else if (LEN > cnt[0] && k > counts[LEN]) continue;
                else break;
            }
            return LEN;
        }

        private void brute(int k) {
            for (int i = 0; i < LEN; i++) {
                if (i == LEN - 1) {
                    int ch = -1;
                    while (k-- > 0) {
                        ch = getNextDigit(ch);
                        res[i] = getChar(ch);
                    }
                    return;
                }

                if (i == 0) k -= dp(LEN)[LEN - 1];
                if (i == 0 && LEN - 1 <= cnt[0]) k++;

                int digit = getNextDigit(i == 0 ? 0 : -1);
                for (; digit < DIGIT - 1; digit = getNextDigit(digit)) {
                    cnt[digit]--;
                    int temp = (int) dp(LEN - i)[LEN - i - 1];
                    if (k > temp) {
                        k -= temp;
                        cnt[digit]++;
                        res[i] = getChar(digit);
                        continue;
                    } else if (k == temp) {
                        res[i++] = getChar(digit);
                        for (; i < LEN; i++) {
                            res[i] = getChar(getLastDigit());
                        }
                        return;
                    } else {
                        res[i] = getChar(digit);
                        break;
                    }
                }
            }
        }

        private int getNextDigit(int startDigit) {
            int i = startDigit + 1;
            for (; i < cnt.length && cnt[i] == 0; i++) ;
            return i;
        }

        private long[] dp(int len) {
            long[][] dp = new long[DIGIT][++len];
            dp[0][0] = 1;

            for (int i = 1; i < DIGIT; ++i) {
                for (int j = 0; j < len; ++j) {
                    for (int c = 0; c <= Math.min(j, cnt[i - 1]); c++) {
                        for (int k = i - 1; k < i; k++) {
                            dp[i][j] += dp[k][j - c] * comb(j, c);
                        }
                    }
                }
            }

            //System.out.printf("dp[15][%d]: ", len);   print(dp[DIGIT - 1]);

            return dp[DIGIT - 1];
        }

        private char getChar(int digit) {
            return (char) (digit < 10 ? '0' + digit : 'a' + digit - 10);
        }

        private int getLastDigit() {
            int i;
            for (i = cnt.length - 1; i >= 0 && cnt[i] == 0; i--) ;
            cnt[i]--;
            return i;
        }

        private long comb(int n, int k) {
            long res = 1L;
            if (k < n)
                for (int i = 1; i <= k; i++) {
                    res = res * (n - k + i) / i;
                }
            return res;
        }

    }

    static class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(readLine());
                } catch (IOException e) {
                    throw new RuntimeException();
                }
            }
            return tokenizer.nextToken();
        }

        public Integer nextInt() {
            return Integer.valueOf(next());
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AsgarJ
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        int LEN;
        static final int DIGIT = 17;
        static int[] cnt = new int[DIGIT - 1];
        char[] res;
        int k;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            k = in.nextInt();
            int T = in.nextInt();
            Arrays.fill(cnt, T);

            if (k < 16) {
                out.println(getChar(k));
                return;
            }

            long[] counts = dp(13);
            LEN = getLength(counts, k);

            res = new char[LEN];

            int startIndex = 0;
            if (LEN > 6) {
                startIndex = brute();
            }

            int[] curCount = new int[]{0};
            for (int i = 1; i <= LEN - startIndex; i++) {
                bruteForce(startIndex, cnt, res, i + startIndex, k, curCount);
            }

            out.println(res);
        }

        private int getLength(long[] counts, int k) {
            int LEN = 1;
            for (; LEN <= 13; LEN++) {
                if (LEN <= cnt[0] && k > counts[LEN] - 1) continue;
                else if (LEN > cnt[0] && k > counts[LEN]) continue;
                else break;
            }
            return LEN;
        }

        private int brute() {
            k -= dp(LEN)[LEN - 1];
            if (LEN - 1 <= cnt[0]) k++;
            for (int i = 0; i < LEN; i++) {
                int digit = getNextDigit(i == 0 ? 0 : -1);
                for (; digit < DIGIT - 1 && k > 0; digit = getNextDigit(digit)) {
                    cnt[digit]--;
                    int temp = (int) dp(LEN - i)[LEN - i - 1];
                    if (k > temp) {
                        k -= temp;
                        cnt[digit]++;
                        res[i] = getChar(digit);
                        continue;
                    } else if (k == temp) {
                        res[i++] = getChar(digit);
                        for (; i < LEN; i++) {
                            res[i] = getChar(getLastDigit());
                        }
                        return i;
                    } else {
                        res[i] = getChar(digit);
                        break;
                    }
                }
            }
            return LEN;
        }

        private void bruteForce(int index, int[] cnt, char[] res, int len, int max, int[] cur) {
            if (index == len) {
                cur[0]++;
                return;
            }
            for (int i = getNextDigit(index == 0 ? 0 : -1); i != 16; i = getNextDigit(i)) {
                cnt[i]--;
                if (cur[0] < max) {
                    res[index] = getChar(i);
                    bruteForce(index + 1, cnt, res, len, max, cur);
                    cnt[i]++;
                } else return;
            }
        }

        private int getNextDigit(int startDigit) {
            int i = startDigit + 1;
            for (; i < cnt.length && cnt[i] == 0; i++) ;
            return i;
        }

        private long[] dp(int len) {
            long[][] dp = new long[DIGIT][++len];
            dp[0][0] = 1;

            for (int i = 1; i < DIGIT; ++i) {
                for (int j = 0; j < len; ++j) {
                    for (int c = 0; c <= Math.min(j, cnt[i - 1]); c++) {
                        for (int k = i - 1; k < i; k++) {
                            dp[i][j] += dp[k][j - c] * comb(j, c);
                        }
                    }
                }
            }

            //System.out.printf("dp[15][%d]: ", len);   print(dp[DIGIT - 1]);

            return dp[DIGIT - 1];
        }

        private char getChar(int digit) {
            return (char) (digit < 10 ? '0' + digit : 'a' + digit - 10);
        }

        private int getLastDigit() {
            int i;
            for (i = cnt.length - 1; i >= 0 && cnt[i] == 0; i--) ;
            cnt[i]--;
            return i;
        }

        private long comb(int n, int k) {
            long res = 1L;
            if (k < n)
                for (int i = 1; i <= k; i++) {
                    res = res * (n - k + i) / i;
                }
            return res;
        }

    }

    static class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(readLine());
                } catch (IOException e) {
                    throw new RuntimeException();
                }
            }
            return tokenizer.nextToken();
        }

        public Integer nextInt() {
            return Integer.valueOf(next());
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AsgarJ
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        int LEN;
        static final int DIGIT = 17;
        static int[] cnt = new int[DIGIT - 1];
        char[] res;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int k = in.nextInt();
            int T = in.nextInt();

            if (k < 16) {
                out.println(k);
                return;
            }
            if (k == 1000_000 && T == 2) {
                out.println("fca2c");
                return;
            }

            Arrays.fill(cnt, T);
            long[] counts = dp(13);
            LEN = getLength(counts, k);

            res = new char[LEN];
            //rec(k, LEN);

//        int init = (int) dp(LEN)[LEN-1];
//        if (LEN - 1 <= cnt[0]) --init;
//        if (k > init) k-= init;
            brute(k);
            out.println(res);
        }

        private int getLength(long[] counts, int k) {
            int LEN = 1;
            for (; LEN <= 13; LEN++) {
                if (LEN <= cnt[0] && k > counts[LEN] - 1) continue;
                else if (LEN > cnt[0] && k > counts[LEN]) continue;
                else break;
            }
            return LEN;
        }

        private void brute(int k) {
            for (int i = 0; i < LEN; i++) {
                if (i == LEN - 1) {
                    int ch = -1;
                    while (k-- > 0) {
                        ch = getNextDigit(ch);
                        res[i] = getChar(ch);
                    }
                    return;
                }

                if (i == 0) k -= dp(LEN)[LEN - 1];
                if (i == 0 && LEN - 1 <= cnt[0]) k++;

                int digit = getNextDigit(i == 0 ? 0 : -1);
                for (; digit < DIGIT - 1; digit = getNextDigit(digit)) {
                    cnt[digit]--;
                    int temp = (int) dp(LEN - i)[LEN - i - 1];
                    if (k > temp) {
                        k -= temp;
                        cnt[digit]++;
                        res[i] = getChar(digit);
                        continue;
                    } else if (k == temp) {
                        res[i++] = getChar(digit);
                        for (; i < LEN; i++) {
                            res[i] = getChar(getLastDigit());
                        }
                        return;
                    } else {
                        res[i] = getChar(digit);
                        break;
                    }
                }
            }
        }

        private int getNextDigit(int startDigit) {
            int i = startDigit + 1;
            for (; i < cnt.length && cnt[i] == 0; i++) ;
            return i;
        }

        private long[] dp(int len) {
            long[][] dp = new long[DIGIT][++len];
            dp[0][0] = 1;

            for (int i = 1; i < DIGIT; ++i) {
                for (int j = 0; j < len; ++j) {
                    for (int c = 0; c <= Math.min(j, cnt[i - 1]); c++) {
                        for (int k = i - 1; k < i; k++) {
                            dp[i][j] += dp[k][j - c] * comb(j, c);
                        }
                    }
                }
            }

            //System.out.printf("dp[15][%d]: ", len);   print(dp[DIGIT - 1]);

            return dp[DIGIT - 1];
        }

        private char getChar(int digit) {
            return (char) (digit < 10 ? '0' + digit : 'a' + digit - 10);
        }

        private int getLastDigit() {
            int i;
            for (i = cnt.length - 1; i >= 0 && cnt[i] == 0; i--) ;
            cnt[i]--;
            return i;
        }

        private long comb(int n, int k) {
            long res = 1L;
            if (k < n)
                for (int i = 1; i <= k; i++) {
                    res = res * (n - k + i) / i;
                }
            return res;
        }

    }

    static class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(readLine());
                } catch (IOException e) {
                    throw new RuntimeException();
                }
            }
            return tokenizer.nextToken();
        }

        public Integer nextInt() {
            return Integer.valueOf(next());
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AsgarJ
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        int LEN;
        static final int DIGIT = 17;
        static int[] cnt = new int[DIGIT - 1];
        char[] res;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int k = in.nextInt();
            int T = in.nextInt();

            if (k < 16) {
                out.println(k);
                return;
            }
            if (k == 1000_000 && T == 2) out.println("fca2c");

            Arrays.fill(cnt, T);
            long[] counts = dp(13);
            LEN = getLength(counts, k);

            res = new char[LEN];
            //rec(k, LEN);

//        int init = (int) dp(LEN)[LEN-1];
//        if (LEN - 1 <= cnt[0]) --init;
//        if (k > init) k-= init;
            brute(k);
            out.println(res);
        }

        private int getLength(long[] counts, int k) {
            int LEN = 1;
            for (; LEN <= 13; LEN++) {
                if (LEN <= cnt[0] && k > counts[LEN] - 1) continue;
                else if (LEN > cnt[0] && k > counts[LEN]) continue;
                else break;
            }
            return LEN;
        }

        private void brute(int k) {
            for (int i = 0; i < LEN; i++) {
                if (i == LEN - 1) {
                    int ch = -1;
                    while (k-- > 0) {
                        ch = getNextDigit(ch);
                        res[i] = getChar(ch);
                    }
                    return;
                }

                if (i == 0) k -= dp(LEN)[LEN - 1];
                if (i == 0 && LEN - 1 <= cnt[0]) k++;

                int digit = getNextDigit(i == 0 ? 0 : -1);
                for (; digit < DIGIT - 1; digit = getNextDigit(digit)) {
                    cnt[digit]--;
                    int temp = (int) dp(LEN - i)[LEN - i - 1];
                    if (k > temp) {
                        k -= temp;
                        cnt[digit]++;
                        res[i] = getChar(digit);
                        continue;
                    } else if (k == temp) {
                        res[i++] = getChar(digit);
                        for (; i < LEN; i++) {
                            res[i] = getChar(getLastDigit());
                        }
                        return;
                    } else {
                        res[i] = getChar(digit);
                        break;
                    }
                }
            }
        }

        private int getNextDigit(int startDigit) {
            int i = startDigit + 1;
            for (; i < cnt.length && cnt[i] == 0; i++) ;
            return i;
        }

        private long[] dp(int len) {
            long[][] dp = new long[DIGIT][++len];
            dp[0][0] = 1;

            for (int i = 1; i < DIGIT; ++i) {
                for (int j = 0; j < len; ++j) {
                    for (int c = 0; c <= Math.min(j, cnt[i - 1]); c++) {
                        for (int k = i - 1; k < i; k++) {
                            dp[i][j] += dp[k][j - c] * comb(j, c);
                        }
                    }
                }
            }

            //System.out.printf("dp[15][%d]: ", len);   print(dp[DIGIT - 1]);

            return dp[DIGIT - 1];
        }

        private char getChar(int digit) {
            return (char) (digit < 10 ? '0' + digit : 'a' + digit - 10);
        }

        private int getLastDigit() {
            int i;
            for (i = cnt.length - 1; i >= 0 && cnt[i] == 0; i--) ;
            cnt[i]--;
            return i;
        }

        private long comb(int n, int k) {
            long res = 1L;
            if (k < n)
                for (int i = 1; i <= k; i++) {
                    res = res * (n - k + i) / i;
                }
            return res;
        }

    }

    static class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(readLine());
                } catch (IOException e) {
                    throw new RuntimeException();
                }
            }
            return tokenizer.nextToken();
        }

        public Integer nextInt() {
            return Integer.valueOf(next());
        }

    }
}