#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k, kol = 0;
  cin >> n >> k;
  map<pair<int, int>, int> m;
  vector<pair<int, int> > v;
  for (int i = 1; i <= n; i++) {
    kol = 0;
    for (int j = 1; j <= n && kol < k; j++) {
      if (!m[make_pair(i, j)] && i != j) {
        v.push_back(make_pair(i, j));
        m[make_pair(i, j)] = 1;
        m[make_pair(j, i)] = 1;
        kol++;
      }
    }
  }
  int a[1005];
  for (int i = 0; i < 1005; i++) a[i] = 0;
  for (int i = 0; i < v.size(); i++) a[v[i].first]++;
  for (int i = 1; i <= n; i++)
    if (a[i] != k) return printf("-1"), 0;
  printf("%d\n", v.size());
  for (int i = 0; i < v.size(); i++) printf("%d %d\n", v[i].first, v[i].second);
  return 0;
}
