#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
bool vis[N][N];
struct Node {
  int x, y;
} a[N * N];
int main() {
  int n, k;
  int cnt = 0;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) vis[i][i] = true;
  for (int i = 1; i <= n; i++) {
    int t = 0;
    for (int j = 1; j <= n; j++) {
      if (t == k) break;
      if (!vis[i][j] || !vis[j][i]) {
        vis[i][j] = true;
        vis[j][i] = true;
        a[++cnt].x = i;
        a[cnt].y = j;
        t++;
      }
    }
    if (t < k) {
      printf("-1\n");
      return 0;
    }
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= cnt; i++) {
    printf("%d %d\n", a[i].x, a[i].y);
  }
  return 0;
}
