Cow IDs

Interview

Time limit1sMemory limit128 MB

Summary
Find the N-th smallest binary number that has exactly K one-bits and no leading zeros, then print it in binary.
Level

Medium5 of 10

Topics
Combinatorics, Math, Bit manipulation, Implementation
Solved
No attempts yet

Problem

Farmer John, a secret computer geek, labels every one of his cows with a binary number. Being a little superstitious, he only uses binary numbers that contain exactly KK one-bits (1≤K≤101 \le K \le 10). As with any binary number, the most significant bit of a label is always 11 (there are no leading zeros).

Farmer John hands out labels in increasing numeric order, beginning with the smallest valid label — the KK-bit number whose bits are all 11. He has lost track of his numbering and needs your help: determine the NN-th label he assigns (1≤N≤1071 \le N \le 10^7).

Input

One line containing two space-separated integers NN and KK.

Output

Output a single line containing the NN-th label written in binary — a string of the characters 0 and 1 with no leading zeros.

Note

Listing the binary numbers with exactly three 11-bits in increasing order gives 111,1011,1101,1110,10011,10101,10110,…111, 1011, 1101, 1110, 10011, 10101, 10110, \dots The 77-th of these is 1011010110.

Examples6

  1. Example 1

    Input
    7 3
    
    Expected output
    10110
    
  2. Example 2

    Input
    1 1
    
    Expected output
    1
    
  3. Example 3

    Input
    1 3
    
    Expected output
    111
    
  4. Example 4

    Input
    1 10
    
    Expected output
    1111111111
    
  5. Example 5

    Input
    4 3
    
    Expected output
    1110
    
  6. Example 6

    Input
    5 2
    
    Expected output
    1010