#include <bits/stdc++.h>
using namespace std;
vector<int> adj[1005];
int w[1005];
int main() {
  int n, k;
  cin >> n >> k;
  if (n - k - 1 < k) return cout << -1, 0;
  cout << n * k << endl;
  for (int i = 1; i <= n; i++) {
    int t = w[i];
    for (int j = i + 1; j <= n; j++) {
      if (w[i] < k)
        printf("%d %d\n", i, j), w[i]++;
      else if (w[j] < k)
        printf("%d %d\n", j, i), w[j]++;
    }
  }
  return 0;
}
