/* -*- coding: utf-8 -*-
 *
 * 1981.cc:  No.1981 [Cherry 4th Tune N] アルゴリズムが破滅する例 - yukicoder
 */

#include<cstdio>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_N = 500;
const int MAX_M = MAX_N * 2;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

pii ops[MAX_M];

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  if (k < (n + 1) / 2) { puts("-1"); return 0; }

  int m = 0;
  for (int i = 0, r = n; r > k; r--, i += 2)
    ops[m++] = pii(i, i + 1);

  for (int i = 0; i < n; i++)
    ops[m++] = pii(i, i);

  printf("%d\n", m);
  for (int i = 0; i < m; i++)
    printf("%d %d\n", ops[i].first + 1, ops[i].second + 1);
  return 0;
}