#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > ans;
bool visit[1111][1111];
int main() {
  int n, k, m;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    int cont = 0;
    for (int j = 1; j <= n && cont < k; j++) {
      if (i == j) continue;
      if (visit[i][j]) continue;
      cont++;
      visit[i][j] = visit[j][i] = true;
      ans.push_back(make_pair(i, j));
    }
    if (cont < k) {
      printf("-1\n");
      return 0;
    }
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++)
    printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
