#include <bits/stdc++.h>
using namespace std;
int n, k;
bool vis[1024];
bool g[1024][1024];
void go(int v, vector<pair<int, int> >& ans, vector<int>& c) {
  for (int v = 1; v <= n; v++) {
    for (int i = 1; i <= n; i++) {
      if (i != v && g[i][v] == 0) {
        if (c[v]) {
          c[v]--;
          g[i][v] = g[v][i] = true;
          ans.push_back({v, i});
        } else if (c[i]) {
          c[i]--;
          g[i][v] = g[v][i] = true;
          ans.push_back({i, v});
        }
      }
    }
  }
}
int main() {
  cin >> n >> k;
  if (k >= n) {
    cout << "-1";
    return 0;
  }
  vector<pair<int, int> > ans;
  int p;
  vector<int> c(n + 1, k);
  go(1, ans, c);
  for (int i = 1; i <= n; i++) {
    if (c[i]) {
      cout << "-1";
      return 0;
    }
  }
  cout << ans.size() << "\n";
  for (auto& m : ans) {
    cout << m.first << " " << m.second << "\n";
  }
  return 0;
}
