#include <bits/stdc++.h>
using namespace std;
int n, k, a[10010];
bool vs[3000][3000];
int main() {
  cin >> n >> k;
  for (int i = n + 1; i <= n + k; i++) {
    a[i] = i - n;
  }
  for (int i = 1; i <= n; i++) a[i] = i;
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= i + k; j++) {
      if (!vs[a[i]][a[j]] && !vs[a[j]][a[i]]) {
        vs[a[i]][a[j]] = true;
        vs[a[j]][a[i]] = true;
      } else {
        cout << -1;
        exit(0);
      }
    }
  }
  if (n == 1) {
    cout << -1;
    exit(0);
  }
  cout << n * k << '\n';
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= i + k; j++) cout << a[i] << " " << a[j] << '\n';
}
