#include <bits/stdc++.h>
using namespace std;


//TEMPLATE
#define pb              push_back
#define mp              make_pair
#define ll              long long
#define ld              long double
//#define pi              3.1415926536
#define pi              acos(-1)
//#define mod             1000000007
#define newline         printf("\n")
#define printminusone   printf("-1\n")
#define scl1(n)         scanf("%lld", &n)
#define scl2(a, b)      scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)   scanf("%lld %lld %lld", &a, &b, &c)
#define printl(n)       printf("%lld\n", n)
#define ssl1(str)       scanf(" %[^\n]", str)
#define scd1(n)         scanf("%lf", &n)
#define scd2(a, b)      scanf("%lf %lf", &a, &b)
#define printd(n)       printf("%lf\n", n)
#define printld(n)      printf("%Lf\n", n)
#define printcase       printf("Case %lld: ", i)
#define reversed(s)     reverse(s.begin(), s.end())
#define asorted(s)      sort(s.begin(), s.end())
#define dsorted(s)      sort(s.begin(), s.end(), cmp)
#define for0(i, n)      for (i = 0; i < n; i++)
#define for1(i, n)      for (i = 1; i <= n; i++)
#define fori(itt, stt)  for(auto itt = stt.begin(); itt != stt.end(); itt++)
#define pii             pair <ll, ll>
#define piii            pair <ll, pii>
//#define SIZE            100005
//#define INF             1000000005
#define F               first
#define S               second
#define FR              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(arr, x)      memset(arr, x, sizeof arr)
#define bitcount(n)     __builtin_popcountll(n)

const ll INF = LLONG_MAX;
const ll SIZE = 4e5+5;
const ll mod = 1e9+7;


ll dp[62][2][62][62];
vector <ll> num;
ll cnt, n;

ll com[62][62];
ll cum[62][62];
void cal_ncr() {
    ll i, j;

    com[0][0] = 1;
    for(i = 1; i < 62; i++) {
        for(j = 0; j <= i; j++) {
            if(j == 0) {
                com[i][j] = 1;
                cum[i][j] = 1;
            }
            else {
                com[i][j] = com[i-1][j-1] + com[i-1][j];
                cum[i][j] = com[i][j] + cum[i][j-1];
            }
        }
    }
}

ll pow2[63];
void cal_pow2() {
    ll i, x = 1, y;
    for0(i, 62) {
        y = x;
        pow2[i] = y;
        x *= 2;
    }
}

string dec_to_binar(ll val) {
    string bin;

    while(val) {
        bin += ((val % 2) + '0');
        val /= 2;
    }
    while(bin.size() < n) bin += '0';
    reversed(bin);

    return bin;
}

ll solve(ll pos, ll small, ll c, ll t) {
    if(c > cnt) return 0;
    if(pos == 61) return(c == cnt);
    if(dp[pos][small][c][t] != -1 && small) return dp[pos][small][c][t];

    ll i, res(0), val = num[pos];
    ll en = small ? 1 : val;


    for0(i, en+1) {
        res += solve(pos+1, small | i < num[pos], c+(i == 1), t);
    }

    return dp[pos][small][c][t] = res;
}

ll cal(ll r) {
    num.clear();

    while(r) {
        num.pb(r%2);
        r /= 2;
    }
    while(num.size() < 61) num.pb(0);
    reversed(num);

//    ms(dp, -1);

    ll res = solve(0, 0, 0, cnt);
    return res;
}

int main() {
    FR;
    cal_ncr();
    cal_pow2();
    ms(dp, -1);
    ll t = 0, m, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0;
    string s, s1, s2;

    while(cin >> n >> m) {
        if(!n && !m) break;

        if(m == 1) {
            for1(i, n) cout << 0;
            cout << "\n";

            continue;
        }

        ll st = 0, en = n;
        cnt = 0;

        while(st <= en) {
            ll mid = (st + en) / 2;

            if(cum[n][mid] >= m) {
                cnt = mid;
                en = mid - 1;
            }
            else st = mid + 1;
        }


        m -= cum[n][cnt-1];
        st = 1, en = pow2[n];

        while(st <= en) {
            ll mid = (st + en) / 2;

            t = cal(mid);

            if(t >= m) {
                ans = mid;
                en = mid - 1;
            }
            else st = mid + 1;
        }

        s = dec_to_binar(ans);
        cout << s << "\n";
    }

    return 0;
}



Measured memory_bytes: 6820