#include <bits/stdc++.h>
using namespace std;
bool vis[1001][1001];
int main() {
  int n, k;
  while (~scanf("%d %d", &n, &k)) {
    if (k > (n - 1) / 2) {
      printf("-1\n");
    } else {
      memset(vis, 0, sizeof(vis));
      int m = k * n;
      printf("%d\n", m);
      for (int i = 0; i < n; ++i) {
        int nex = 1;
        for (int j = 0; j < k; j += 1) {
          while (vis[i + 1][nex] || i + 1 == nex) {
            nex = nex + 1;
            if (nex == n + 1) {
              nex = 1;
            }
          }
          vis[i + 1][nex] = true;
          vis[nex][i + 1] = true;
          printf("%d %d\n", i + 1, nex);
        }
      }
    }
  }
}
