#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 5;
vector<int> v[maxn];
bool mark[maxn][maxn];
int maxgame, n, k;
int go(int root) {
  int tmp = 0;
  for (int i = 1; i <= n && tmp < k; i++)
    if (i != root && !mark[root][i]) {
      tmp++;
      mark[root][i] = mark[i][root] = true;
      v[root].push_back(i);
    }
  return k;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  maxgame = (n * n - 1) / 2;
  if (maxgame < (k * n)) {
    cout << "-1\n";
    exit(0);
  }
  bool flag = true;
  for (int i = 1; i <= n; i++) {
    if (go(i) != k) flag = false;
  }
  if (!flag) {
    cout << "-1\n";
    exit(0);
  }
  cout << n * k << '\n';
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < (int)v[i].size(); j++)
      cout << i << ' ' << v[i][j] << '\n';
  return 0;
}
