Problem:
Score: 500 points

Problem Statement

Does there exist an undirected graph with N vertices satisfying the following conditions?

The graph is simple and connected.

The vertices are numbered 1, 2, ..., N.

Let M be the number of edges in the graph. The edges are numbered 1, 2, ..., M, the length of each edge is 1, and Edge i connects Vertex u_i and Vertex v_i.

There are exactly K pairs of vertices (i,\ j)\ (i < j) such that the shortest distance between them is 2.

If there exists such a graph, construct an example.

Constraints

All values in input are integers.

2 \leq N \leq 100

0 \leq K \leq \frac{N(N - 1)}{2}

Input

Input is given from Standard Input in the following format:

N K

Output

If there does not exist an undirected graph with N vertices satisfying the conditions, print -1.

If there exists such a graph, print an example in the following format (refer to Problem Statement for what the symbols stand for):

M
u_1 v_1
:
u_M v_M

If there exist multiple graphs satisfying the conditions, any of them will be accepted.

Sample Input 1

5 3

Sample Output 1

5
4 3
1 2
3 1
4 5
2 3

This graph has three pairs of vertices such that the shortest distance between them is 2: (1,\ 4), (2,\ 4), and (3,\ 5). Thus, the condition is satisfied.

Sample Input 2

5 8

Sample Output 2

-1

There is no graph satisfying the conditions.

Solution in Rust (1.15.1) (judge verdict: Accepted)

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn solve(n: u64, k: u64) -> Option<Vec<(u64, u64)>> {
    if k > (n - 1) * (n - 2) / 2 {
        return None;
    }

    let mut ans = (2..(n + 1)).map(|i| (1, i)).collect::<Vec<(u64, u64)>>();

    let times = (n - 1) * (n - 2) / 2 - k;
    let mut cnt = 0;
    let mut s = 2;
    let mut e = 3;

    while cnt < times {
        ans.push((s, e));
        if e == n {
            s += 1;
            e = s + 1;
        } else {
            e += 1;
        }
        cnt += 1;
    }

    Some(ans)
}

fn main() {
    let (n, k) = parse_line!(u64, u64);
    match solve(n, k) {
        Some(vec) => {
            println!("{}", vec.len());
            for e in vec {
                println!("{} {}", e.0, e.1);
            }
        }
        None => println!("-1"),
    }
}

#[test]
fn solve_test() {
    assert_eq!(
        solve(5, 3),
        Some(vec![(1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5)])
    );

    assert_eq!(solve(2, 0), Some(vec![(1, 2)]));
}