Roads, or There and Back Again
In Berlandia, there are N cities, numbered from 1 to N. These cities are connected by N-1 one-way roads, arranged sequentially from the last city to the first: the N-th city is connected to the (N-1)-th, and so on, down to the 2-nd city connecting to the 1-st.
The President of Berlandia is not satisfied with this setup. He insists that it should be possible to travel between any two cities using the roads.
To address this, the council of ministers must devise a plan to add a set of one-way roads that will fulfill the President's requirement.
The President, however, is cost-conscious and will only approve a plan that is efficient. He will reject any plan if it contains roads that can be removed without affecting the connectivity requirement. Additionally, he will reject a plan if any two roads (a, b) and (b, c) can be replaced by a single road (a, c).
Moreover, the President demands order, so the roads in the plan must be listed in lexicographical order. This means that roads are sorted first by the starting city, and if they are the same, by the ending city. For instance, the road (11, 3) is lexicographically greater than (9, 3), but less than (11, 11).
This year, the President is turning K years old, and the council has decided to present the K-th lexicographically smallest plan that meets his criteria. Plans are compared lexicographically as sequences of roads. For example, the plan {(1, 10), (7, 20)} is lexicographically smaller than {(1, 20)}, but larger than {(1, 10), (7, 9), (8, 15)} (note that some plans in this example do not meet the President's requirements and are provided only for illustrating the order of comparison).
We need your assistance to solve this task.
Input
The first line contains two integers N and K (2 ≤ N ≤ 50, 1 ≤ K ≤ 10^9).
Output
On the first line, output Q - the number of roads in the desired plan. Then, in the next Q lines, list the roads in the President's preferred lexicographical order. Each road should be represented as a pair of integers. If no solution exists, output -1.