#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[1010][1010];
int in[1010];
int check() {
  for (int t = 1; t < n; ++t) {
    for (int i = 0; i < n; ++i) {
      int j = (i + t) % n;
      if (a[j][i] || a[i][j] || in[i] == m) continue;
      a[i][j] = 1;
      ++in[i];
    }
  }
  for (int i = 0; i < n; ++i)
    if (in[i] != m) return 0;
  int ans = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      if (a[i][j]) ++ans;
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  int ans = check();
  if (ans) {
    printf("%d\n", ans);
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j)
        if (a[i][j]) {
          printf("%d %d\n", i + 1, j + 1);
        }
  } else
    puts("-1");
}
