#include <bits/stdc++.h>
using namespace std;
pair<int, int> p[1000010];
int a[1010];
int main() {
  int n, k;
  while (scanf("%d%d", &n, &k) == 2) {
    for (int i = 1; i <= n; i++) {
      a[i] = k;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
      for (int j = i + 1; j <= n; j++) {
        if (a[i] > 0) {
          a[i]--;
          p[ans++] = make_pair(i, j);
        } else if (a[j] > 0) {
          a[j]--;
          p[ans++] = make_pair(j, i);
        }
      }
    bool flag = true;
    for (int i = 1; i <= n; i++)
      if (a[i]) {
        flag = false;
        break;
      }
    if (!flag) {
      printf("-1\n");
      continue;
    }
    printf("%d\n", ans);
    for (int i = 0; i < ans; i++) printf("%d %d\n", p[i].first, p[i].second);
  }
  return 0;
}
