#include <bits/stdc++.h>
using namespace std;
template <typename T>
void PrintContainer(T a, int n = -1) {
  if (n == -1) n = a.size();
  cout << "{";
  int i = 0;
  for (auto it : a) {
    cout << (it) << ", ";
    if (++i == n) break;
  }
  cout << "}\n";
}
int main() {
  int n, k;
  cin >> n >> k;
  if (k > (n - 1) / 2) {
    cout << -1 << endl;
    exit(0);
  }
  vector<int> greatest_step(n, 0);
  cout << k * n << endl;
  for (int step = 1; step <= k; ++step) {
    int pos = 0, npos;
    for (int i = 0; i < (int)(step); ++i) {
      pos = i;
      while (greatest_step[pos] < step) {
        npos = (pos + step) % n;
        if (greatest_step[npos] == step) {
          greatest_step[pos] = step;
          printf("%i %i \n", pos + 1, npos + 1);
          ++pos;
          break;
        } else {
          printf("%i %i \n", pos + 1, npos + 1);
          greatest_step[pos] = step;
          pos = npos;
        }
      }
    }
  }
}
