#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  register int c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
inline void writeln(int x) {
  char buffor[21];
  register int i = 0;
  int neg = 0;
  if (x < 0) {
    neg = 1;
    x = -x;
  }
  do {
    buffor[i++] = (x % 10) + '0';
    x /= 10;
  } while (x);
  i--;
  if (neg) putchar('-');
  while (i >= 0) putchar(buffor[i--]);
  putchar('\n');
}
int n, k;
void input() { cin >> n >> k; }
void solve() {
  if (k == 1 || k >= 4 || n <= 3) {
    cout << -1;
    return;
  }
  if (k == 3) {
    cout << n - 1 << '\n';
    for (int i = 2; i <= n - 1; i++) cout << 1 << " " << i << '\n';
    cout << 2 << " " << n << '\n';
    return;
  }
  if (k == 2) {
    if (n == 4) {
      cout << -1;
      return;
    };
    cout << 2 * n - 4 << '\n';
    for (int i = 2; i <= n - 2; i++) cout << 1 << " " << i << '\n';
    for (int i = 3; i <= n - 1; i++) cout << n << " " << i << '\n';
    cout << 2 << " " << n - 1 << '\n';
    cout << 1 << " " << n << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  input();
  solve();
  return 0;
}
