#include <bits/stdc++.h>
using namespace std;
int table[1005][1005];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  if ((n == 1) || (n == 2)) {
    cout << -1 << endl;
    return 0;
  }
  int m = 0;
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    cnt = 0;
    for (int j = 0; j < n; ++j) {
      if (i == j) continue;
      if ((i != j) && (table[j][i] == 0)) {
        table[i][j] = 1;
        ++cnt;
        ++m;
      }
      if (cnt == k) break;
    }
    if (cnt < k) {
      printf("-1\n");
      return 0;
    }
  }
  printf("%d\n", m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (table[i][j] == 1) {
        printf("%d %d\n", i + 1, j + 1);
      }
    }
  }
  return 0;
}
