#include <bits/stdc++.h>
const int N = 1005;
int n, K;
int w[N][N];
std::vector<int> ansx, ansy;
int main() {
  memset(w, -1, sizeof w);
  bool f = true;
  scanf("%d%d", &n, &K);
  for (int i = 1; i <= n; ++i) {
    int cnt = K;
    for (int j = 1; j <= n && cnt > 0; ++j)
      if (j != i && w[i][j] == -1) {
        --cnt;
        w[i][j] = 1;
        w[j][i] = 0;
        ansx.push_back(i);
        ansy.push_back(j);
      }
    if (cnt != 0) {
      f = false;
      break;
    }
  }
  if (!f)
    puts("-1");
  else {
    printf("%d\n", ansx.size());
    for (int i = 0; i < ansx.size(); ++i) printf("%d %d\n", ansx[i], ansy[i]);
  }
  return 0;
}
