#include <bits/stdc++.h>
using namespace std;
bool used[1005][1005];
vector<pair<int, int> > ans;
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) used[i][j] = false;
  ans.clear();
  for (int i = 1; i <= n; ++i) {
    int cnt = 0;
    for (int j = 1; j <= n; ++j) {
      if (cnt < k and i != j and !used[i][j]) {
        used[i][j] = used[j][i] = true;
        ++cnt;
        ans.push_back(make_pair(i, j));
      }
    }
    if (cnt != k) {
      puts("-1");
      return 0;
    }
  }
  printf("%d\n", (int)ans.size());
  for (int i = 0; i < ans.size(); ++i)
    printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
