#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > V;
map<pair<int, int>, int> M;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  bool good = true;
  for (int i = 1; i <= n; i++) {
    int curr = i;
    int left = k;
    while (left > 0) {
      curr++;
      if (curr > n) curr -= n;
      if (curr == i) break;
      if (curr != i) {
        pair<int, int> p1 = make_pair(min(curr, i), max(curr, i));
        if (M[p1])
          continue;
        else
          M[p1] = 1;
        V.push_back(make_pair(i, curr));
        left--;
      }
    }
    if (left > 0) good = false;
  }
  if (!good) {
    printf("-1\n");
    return 0;
  }
  printf("%d\n", V.size());
  for (int i = 0; i < V.size(); i++) {
    printf("%d %d\n", V[i].first, V[i].second);
  }
  return 0;
}
