#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 7;
int n, k;
int book[N];
int flag = 0;
int main() {
  cin >> n >> k;
  if ((k * n) > (n * (n - 1) / 2))
    printf("-1\n");
  else {
    printf("%d\n", n * k);
    int i = 1, j = 2, ans = 1;
    for (; ans <= k; ans++, j++) {
      book[flag++] = i;
      book[flag++] = j;
    }
    for (i = flag; i < n * k * 2; i += 2) {
      book[i] = book[i - flag] + 1;
      book[i + 1] = book[i + 1 - flag] + 1;
      if (book[i + 1] > n) book[i + 1] -= n;
    }
    for (i = 0; i < n * k * 2; i += 2) printf("%d %d\n", book[i], book[i + 1]);
  }
  return 0;
}
