#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > vec;
int par[1004];
int main() {
  int n, k, i, j;
  scanf("%d%d", &n, &k);
  set<pair<int, int> > myset;
  for (i = 1; i <= n; i++) {
    int count = 0;
    j = 1;
    while (j <= n && count < k) {
      if (i == j) {
        j++;
        continue;
      }
      if (myset.find(make_pair(i, j)) != myset.end()) {
        j++;
        continue;
      }
      vec.push_back(make_pair(i, j));
      myset.insert(make_pair(j, i));
      count++;
      j++;
    }
    if (count < k) {
      printf("-1\n");
      return 0;
    }
  }
  int len = vec.size();
  printf("%d\n", len);
  for (i = 0; i < len; i++) printf("%d %d\n", vec[i].first, vec[i].second);
  return 0;
}
