#include <bits/stdc++.h>
using namespace std;
const int maxn = 1211;
const int inf = 0x7f7f7f7f;
const int mod = (int)(1e9 + 7);
const double eps = 1e-8;
const double pi = acos(-1.0);
const int mask = 65535;
int deg[maxn];
bool g[maxn][maxn];
pair<int, int> E[maxn * maxn];
int m;
int main() {
  ios::sync_with_stdio(false);
  int n, k, i, j;
  cin >> n >> k;
  int h = (n - 1) >> 1;
  if (k > h) {
    cout << "-1" << endl;
    return 0;
  }
  for (i = 0; i < n; ++i) {
    for (j = 0; j < n; ++j) {
      if (i == j) continue;
      if (g[i][j]) continue;
      if (deg[i] >= k) continue;
      g[i][j] = g[j][i] = true;
      E[m].first = i + 1;
      E[m].second = j + 1;
      ++m;
      ++deg[i];
    }
  }
  for (i = 0; i < n; ++i) {
    if (deg[i] ^ k) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << m << endl;
  for (i = 0; i < m; ++i) {
    cout << E[i].first << " " << E[i].second << endl;
  }
  return 0;
}
