#ARC152D. [ARC152D] Halftree

[ARC152D] Halftree

Score : 700700 points

Problem Statement

We have an undirected graph with NN vertices numbered 00 through N1N-1 and no edges at first. You may add edges to this graph as you like. When you are done with adding edges, the following operation will be performed once using a given integer KK.

  • For each edge you have added, let uu and vv be its endpoints, and an edge will be added between two vertices (u+K)(u+K) mod\mathrm{mod} NN and (v+K)(v+K) mod\mathrm{mod} NN. This edge will be added even if there is already an edge between these vertices, resulting in multi-edges.

For the given NN and KK, find a set of edges that you should add so that the graph will be a tree after the operation. If there is no such set of edges, indicate that fact.

Constraints

  • 2N2×1052\leq N\leq 2\times 10^5
  • 1KN11\leq K\leq N-1
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN KK

Output

If there is a set of edges that satisfies the requirement, let MM be the number of edges, and aia_i and bib_i be the two vertices connected by the ii-th edge, and print a solution in the following format. Here, 0MN0\leq M\leq N must hold, and all values must be integers. The edges may be printed in any order, as well as the endpoints of an edge.

MM

a1a_1 b1b_1

a2a_2 b2b_2

\vdots

aMa_M bMb_M

If multiple solutions exist, any of them will be accepted.

If no set of edges satisfies the requirement, print -1.

5 2
2
2 3
2 4

The operation will add the edges 44-00 and 44-11. Then, the graph will be a tree, so this is a legitimate output.

2 1
-1

There is no way to have a tree after the operation.

7 1
3
0 1
2 3
4 5