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