#include <bits/stdc++.h>
using namespace std;
unordered_set<int> in[1005], out[1005];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  if (k + k > n - 1) {
    puts("-1");
  } else {
    int m = n * k;
    for (int i = 1; i <= n; ++i) {
      for (int j = 1, p = 0; p < k && j <= n; ++j) {
        if (j == i || in[i].count(j) || out[i].count(j) || out[j].count(i) ||
            in[j].count(i))
          continue;
        if (in[i].size() == k || out[j].size() == k) continue;
        in[i].insert(j);
        out[j].insert(i);
        ++p;
      }
      for (int j = n, p = 0; p < k && j >= 1; --j) {
        if (j == i || in[i].count(j) || out[i].count(j) || out[j].count(i) ||
            in[j].count(i))
          continue;
        if (out[i].size() == k || in[j].size() == k) continue;
        out[i].insert(j);
        in[j].insert(i);
        ++p;
      }
    }
    printf("%d\n", m);
    for (int i = 1; i <= n; ++i)
      for (auto j : in[i]) printf("%d %d\n", i, j);
  }
  return 0;
}
