import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readLine >>= printRes . solve
    where
        printRes (m, vs)
            | m == -1 = print m
            | otherwise = print m >> mapM_ (B.putStrLn . B.unwords . map (B.pack . show)) vs

solve :: [Int] -> (Int, [[Int]])
solve [n, k] 
    | k > an = (-1, [])
    | otherwise = (m, es)
    where
        an = ((n - 2) * (n - 1)) `div` 2
        m = n - 1 + an - k 
        es = addEdges base (an - k) 2 3
        base = map (\x -> [1, x]) [2..n] 
        addEdges acc c v u
            | u > n = addEdges acc c (v + 1) (v + 2)
            | c > 0 = addEdges ([v, u] : acc) (c - 1) v (u + 1)
            | otherwise = acc

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine