#include <bits/stdc++.h>
using namespace std;
bool visit[1002][1002];
int n, k;
vector<pair<int, int> > vect;
void cal() {
  int i, j;
  for (i = 1; i <= n; i++) {
    int x = 0;
    for (j = 1; j <= n; j++) {
      if (i != j && visit[i][j] == false && x < k) {
        vect.push_back(make_pair(i, j));
        visit[i][j] = true;
        visit[j][i] = true;
        x++;
      }
    }
  }
}
int main() {
  int i, total;
  scanf("%d %d", &n, &k);
  total = (n * (n - 1)) / 2;
  if (k * n > total) {
    printf("-1\n");
    return 0;
  }
  cal();
  printf("%d\n", vect.size());
  for (i = 0; i < vect.size(); i++)
    printf("%d %d\n", vect[i].first, vect[i].second);
  return 0;
}
