#include <bits/stdc++.h>
int const MAXN = 1024;
std::set<int> a[MAXN], w[MAXN];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j)
      if (i != j) a[i].insert(j);
  }
  for (int i = 0; i < n; ++i) {
    std::set<int>::const_iterator it = a[i].begin();
    for (int j = 0; j < k; ++j) {
      if (it == a[i].end()) {
        printf("-1\n");
        return 0;
      }
      int v = *it;
      a[v].erase(i);
      w[i].insert(v);
      ++it;
    }
  }
  int count = 0;
  for (int i = 0; i < n; ++i) count += w[i].size();
  printf("%d\n", count);
  for (int i = 0; i < n; ++i) {
    for (std::set<int>::const_iterator it = w[i].begin(); it != w[i].end();
         ++it)
      printf("%d %d\n", i + 1, *it + 1);
  }
  return 0;
}
