#include <bits/stdc++.h>
const int MAX_N = int(1e3) + 7;
using namespace std;
int n, k, win[MAX_N];
bool g[MAX_N][MAX_N];
vector<pair<int, int> > sol;
bool fail() {
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (i == j || g[i][j]) continue;
      g[i][j] = g[j][i] = true;
      if (win[i] < k) {
        sol.push_back(make_pair(i + 1, j + 1));
        ++win[i];
      } else if (win[j] < k) {
        sol.push_back(make_pair(j + 1, i + 1));
        ++win[j];
      }
    }
    if (win[i] < k) return true;
  }
  return false;
}
int main() {
  scanf("%d %d", &n, &k);
  if (fail())
    printf("-1\n");
  else {
    printf("%d\n", (int)sol.size());
    for (auto &i : sol) printf("%d %d\n", i.first, i.second);
  }
  return 0;
}
