#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, k, win[N], lost[N];
vector<int> games;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) win[i] = k, lost[i] = (n - 1) - k;
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j)
      if (i != j) {
        if (win[i] > 0 && lost[j] > 0) {
          win[i]--;
          lost[j]--;
          games.push_back(i);
          games.push_back(j);
        }
      }
    for (int j = 1; j < i; ++j)
      if (i != j) {
        if (win[i] > 0 && lost[j] > 0) {
          win[i]--;
          lost[j]--;
          games.push_back(i);
          games.push_back(j);
        }
      }
  }
  bool ok = 1;
  for (int i = 1; i <= n; ++i)
    if (win[i] != 0) ok = 0;
  if (ok == 0) {
    cout << "-1\n";
    return 0;
  }
  cout << int(games.size()) / 2 << '\n';
  for (size_t i = 0; i < games.size(); i += 2) {
    cout << games[i] << ' ' << games[i + 1] << '\n';
  }
}
