let () =
    let maxk k = if k < 3 then 0 else (k - 2) * (k - 1) / 2 in
    let main () =
        let n, k = Scanf.sscanf (read_line ()) "%d %d" (fun n k -> n, k) in
        if k > maxk n then Printf.printf "-1\n" else
            if n = 2 then Printf.printf "1\n1 2\n" else (
                let m1 = n - 1 in
                let m2 = maxk n - k in
                Printf.printf "%d\n" (m1 + m2);
                for i = 1 to m1 do
                    Printf.printf "%d %d\n" i n
                done;
                let rec loop i j rest =
                    if rest > 0 then (
                        Printf.printf "%d %d\n" i j;
                        if j + 1 < n then loop i (j + 1) (rest - 1) else
                            loop (i + 1) (i + 2) (rest - 1)
                    )
                in
                loop 1 2 m2
            )
    in
    main ()