One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n teams and played several matches, two teams could not play against each other more than once.

The appointed Judge was the most experienced member — Pavel. But since he was the wisest of all, he soon got bored of the game and fell asleep. Waking up, he discovered that the tournament is over and the teams want to know the results of all the matches.

Pavel didn't want anyone to discover about him sleeping and not keeping an eye on the results, so he decided to recover the results of all games. To do this, he asked all the teams and learned that the real winner was friendship, that is, each team beat the other teams exactly k times. Help Pavel come up with chronology of the tournir that meets all the conditions, or otherwise report that there is no such table.

Input

The first line contains two integers — n and k (1 ≤ n, k ≤ 1000).

Output

In the first line print an integer m — number of the played games. The following m lines should contain the information about all the matches, one match per line. The i-th line should contain two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi). The numbers ai and bi mean, that in the i-th match the team with number ai won against the team with number bi. You can assume, that the teams are numbered from 1 to n.

If a tournir that meets the conditions of the problem does not exist, then print -1.

Examples

Input

3 1


Output

3
1 2
2 3
3 1
import java.awt.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.*;

public class Watermelon {
	public static void main(String[] args) throws IOException{
		Main m=new Main();
		m.solve();
	}
	}
class Main{
	
	static int[] temp=new int[100];
	 BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
	 private int[] array;
	    private int[] tempMergArr;
	    private int length;
	
	   
	    StringTokenizer stringTokenizer;

	     String next() throws IOException {
	        while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
	            stringTokenizer = new StringTokenizer(reader.readLine());
	        }
	        return stringTokenizer.nextToken();
	    }

	    int nextInt() throws IOException {
	        return Integer.parseInt(next());
	    }

	    long nextLong() throws IOException {
	        return Long.parseLong(next());
	    }
	    void solve() throws IOException  {
	    	int n=this.nextInt();
	        int k=this.nextInt();
	        if(n%2!=0){
	        if(n/2<k){
	        	System.out.println(-1);
	        	System.exit(0);
	        }
	        }
	        else{
	        	if(n/2<=k){
		        	System.out.println(-1);
	        	System.exit(0);
		        }
	        }
	        int x=0;
	        int c=2;
	        StringBuilder sb = new StringBuilder();
	        System.out.println(n*k);
	        for(int i=1;i<=n;i++){
	        	for(int j=1;j<=k;j++){
	        		if((i+j)%n==0)
	        		sb.append(n+" "+i+"\n");
	        		else
	        			sb.append((i+j)%n+" "+i+"\n");
	        		
	        	}
	        }
	        System.out.println(sb);
	        
	    }
	    
	      public static double median(double[] m) {
	    	    int middle = m.length/2;
	    	    if (m.length%2 == 1) {
	    	        return m[middle];
	    	    } else {
	    	        return (m[middle-1] + m[middle]) / 2.0;
	    	    }
	    	}
	      private static int add(int x,int y){
	    	  if(x==0&&y==1)
	    		  return 1;
	    	  if(x==1&&y==0)
	    		  return 1;
	    	  if(x==0&&y==0)
	    		  return 0;
	    	  if(x==1&&y==1)
	    		  return 0;
	    	   return 0;
	      }
	      private static int[] column(int[] arr){
	    	  for(int i=0;i<arr.length;i++)
	    		  arr[i]=(1-arr[i]);	 
	    	  return arr;
	      }
          private static int[] row(int[] arr){
        	  for(int i=0;i<arr.length;i++)
	    		  arr[i]=(1-arr[i]);
        	  return arr;
          }
	private static int gcd(int a, int b)
	{
	    while (b > 0)
	    {
	    	int temp = b;
	        b = a % b; // % is remainder
	        a = temp;
	    }
	    return a;
	}
	private static int lcm(int a, int b)
	{
	    return a * (b / gcd(a, b));
	}
	static int[] toFractionPos(int x,int y){
		int a=gcd(x,y);
		int[] arr={x/a,y/a};
		//display(arr);
		return arr;
	}
   
	static void display(int[][] arr){
		for(int i=0;i<arr.length;i++){
			for(int j=0;j<arr[i].length;j++){
				System.out.print(arr[i][j]+" ");
		}
			System.out.println();
		}
		System.out.println();
	}

	 static void display(String[] arr){
			for(int i=0;i<arr.length;i++){
				System.out.println(arr[i]+" ");
			}	
			//System.out.println();
		
	 }
	 static void display(int[] arr){
		 for(int i=0;i<arr.length;i++)
				System.out.print(arr[i]+" ");
		System.out.println();
		 }
		 static void display(double[] arr){
		 	   for(int i=0;i<arr.length;i++){
		 		   System.out.print(arr[i]+" ");
		 	   }
		 	   System.out.println();
	    }
	 static void display(char[] arr){
		// System.out.println();
		 int t=0;
			for(int i=0;i<arr.length;i++){
				if(arr[i]!='0'){t=i;break;}
			}	
			while(t!=arr.length){
				System.out.print(arr[t]);
				t++;
			}
			System.out.println();
		
		  }
	 static String str(char[] carr){
		 String str="";
		 for(int i=0;i<carr.length;i++){
			    str=str+carr[i];
			}
		 return str;
	 }
	    public void sort(int inputArr[]) {
	        this.array = inputArr;
	        this.length = inputArr.length;
	        this.tempMergArr = new int[length];
	        doMergeSort(0, length - 1);
	    }
	 
	    private void doMergeSort(int lowerIndex, int higherIndex) {
	         
	        if (lowerIndex < higherIndex) {
	            int middle = lowerIndex + (higherIndex - lowerIndex) / 2;
	            // Below step sorts the left side of the array
	            doMergeSort(lowerIndex, middle);
	            // Below step sorts the right side of the array
	            doMergeSort(middle + 1, higherIndex);
	            // Now merge both sides
	            mergeParts(lowerIndex, middle, higherIndex);
	        }
	    }
	 
	    private void mergeParts(int lowerIndex, int middle, int higherIndex) {
	 
	        for (int i = lowerIndex; i <= higherIndex; i++) {
	            tempMergArr[i] = array[i];
	        }
	        int i = lowerIndex;
	        int j = middle + 1;
	        int k = lowerIndex;
	        while (i <= middle && j <= higherIndex) {
	            if (tempMergArr[i] <= tempMergArr[j]) {
	                array[k] = tempMergArr[i];
	                i++;
	            } else {
	                array[k] = tempMergArr[j];
	                j++;
	            }
	            k++;
	        }
	        while (i <= middle) {
	            array[k] = tempMergArr[i];
	            k++;
	            i++;
	        }
	 
	    }
}


 class  Count implements Comparable {
    	    Integer i;
    	    Integer j;

    	    Count(int i,int j){
    	        this.j=j;
    	        this.i=i;
    	    }
    	    void display(){
    	    	System.out.println(i+" "+j);
    	    }
    	    
    	    	@Override
    		public int compareTo(Object o) {
    			// TODO Auto-generated method stub
    			Count c=(Count)o;
    			if(j.compareTo(j)>0)
    				return 1;
    			else if(j.compareTo(j)<0)
    				return -1;
    			else{
    				return 0;
    				
    			}
    		}
    		
    	}

 class  Counti implements Comparable {
    	    Integer i;
    	    int j;
    	    int k;
    	    Counti(int i,int j,int k){
    	        this.j=j;
    	        this.i=i;
    	        this.k=k;
    	    }
    	    void display(){
    	    	System.out.println(i+" "+j+" "+k);
    	    }
    	    
    	    	@Override
    		public int compareTo(Object o) {
    			// TODO Auto-generated method stub
    			Counti c=(Counti)o;
    			if(i.compareTo(c.i)>0)
    				return 1;
    			else if(i.compareTo(c.i)<0)
    	    		return -1;
    			else
    				return 0;
    		}
    		
    	}
		
 class Extra{
	 ArrayList<Integer> list=new ArrayList<>();
	 Extra(int i){
		 list.add(i);
	 }
	 void display(){
		 System.out.println(list.size());
		 for(int i=0;i<list.size();i++){
			 System.out.print(list.get(i)+" ");
		 }
		 System.out.println();
	 }
 }

