# codeforce 8E Beads

One Martian boy called Zorg wants to present a string of beads to his friend from the Earth — Masha. He knows that Masha likes two colours: blue and red, — and right in the shop where he has come, there is a variety of adornments with beads of these two colours. All the strings of beads have a small fastener, and if one unfastens it, one might notice that all the strings of beads in the shop are of the same length. Because of the peculiarities of the Martian eyesight, if Zorg sees one blue-and-red string of beads first, and then the other with red beads instead of blue ones, and blue — instead of red, he regards these two strings of beads as identical. In other words, Zorg regards as identical not only those strings of beads that can be derived from each other by the string turnover, but as well those that can be derived from each other by a mutual replacement of colours and/or by the string turnover.

It is known that all Martians are very orderly, and if a Martian sees some amount of objects, he tries to put them in good order. Zorg thinks that a red bead is smaller than a blue one. Let’s put 0 for a red bead, and 1 — for a blue one. From two strings the Martian puts earlier the string with a red bead in the i-th position, providing that the second string has a blue bead in the i-th position, and the first two beads i - 1 are identical.

At first Zorg unfastens all the strings of beads, and puts them into small heaps so, that in each heap strings are identical, in his opinion. Then he sorts out the heaps and chooses the minimum string in each heap, in his opinion. He gives the unnecassary strings back to the shop assistant and says he doesn’t need them any more. Then Zorg sorts out the remaining strings of beads and buys the string with index k.

All these manupulations will take Zorg a lot of time, that’s why he asks you to help and find the string of beads for Masha.

Input

The input file contains two integers n and k (2 ≤ n ≤ 50;1 ≤ k ≤ 10^16) —the length of a string of beads, and the index of the string, chosen by Zorg.

Output

Output the k-th string of beads, putting 0 for a red bead, and 1 — for a blue one. If it s impossible to find the required string, output the only number -1.

Examples

input

4 4

output

0101

Note

Let’s consider the example of strings of length 4 — 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010, 1011, 1100, 1101, 1110. Zorg will divide them into heaps: {0001, 0111, 1000, 1110}, {0010, 0100, 1011, 1101}, {0011, 1100}, {0101, 1010}, {0110, 1001}. Then he will choose the minimum strings of beads in each heap: 0001, 0010, 0011, 0101, 0110. The forth string — 0101.

题意

将所有二进制串（只允许前导 0）中，同时满足字典序不大于其逆序串，取反串和逆序取反串（三种都要满足）的串提出来，按字典序排序，求第m个。

题解

状态时f[l][r][rev][inv]

表示当前考虑l，r这段区间

rev为1表示现在数字已经比倒过来的大了，反之为0

inv为1表示现在数字已经比倒过来取反的大了，反之为0

里面表示这样的数字有多少种。

我们也就是说我们考虑的数字就是每组数字中最小的那个，我们保证了他会比倒过来和倒过来取反要小。转移的时候有很多条件，就是为了保证这个。

这样枚举每一位填什么就可以了。

```
#include <cstdio>
#include <cstring>
#include <iostream>
#define N 60
using namespace std;
typedef long long ll;
ll f[N][N][2][2],m;
int n,a[100];
bool vis[N][N][2][2];
ll work(int l,int r,int rev,int inv)
{
if (l>r)
return 1;
if (vis[l][r][rev][inv])
return f[l][r][rev][inv];
vis[l][r][rev][inv]=1;
ll &ans=f[l][r][rev][inv];
ans=0;
for (int i=0;i<=1;i++)
if (a[l]==-1 || a[l]==i)
for (int j=0;j<=1;j++)
if (a[r]==-1 || a[r]==j)
if (l<r || i==j)
if (rev || i<=j)
if (inv || i<=1-j)
ans+=work(l+1,r-1,i<j||rev,i<1-j||inv);
return ans;
}
main()
{
cin>>n>>m;
m++;
memset(a,-1,sizeof a);
a[0]=0;
if (work(0,n-1,0,0)<m){puts("-1");return 0;}
for (int i=1;i<n;i++)
{
memset(vis,0,sizeof vis);
a[i]=0;
ll now=work(0,n-1,0,0);
if (now<m)
m-=now,a[i]=1;
}
for (int i=0;i<n;i++)
printf("%d",a[i]);
}
```