#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const long long INF = 1ll << 60, Mo = 1e9 + 7;
int n, m;
int f[2000][2000];
int y[2000], s[2000];
vector<pair<int, int> > W;
int main() {
  scanf("%d%d", &n, &m);
  if (m > (n - 1) / 2) {
    puts("-1");
    return 0;
  }
  int i, j, k;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++)
      if (i != j) {
        if (f[i][j] || f[j][i]) continue;
        if ((n - 1) - s[j] <= m) continue;
        if (y[i] >= m) continue;
        f[i][j] = 1;
        f[j][i] = 1;
        W.push_back(pair<int, int>(i, j));
        y[i]++;
        s[j]++;
      }
  for (i = 1; i <= n; i++)
    if (y[i] < m) {
      puts("-1");
      return 0;
    }
  printf("%d\n", W.size());
  for (i = 0; i < W.size(); i++) printf("%d %d\n", W[i].first, W[i].second);
  return 0;
}
