#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void chkmax(T& x, U y) {
  if (x < y) x = y;
}
template <typename T, typename U>
inline void chkmin(T& x, U y) {
  if (y < x) x = y;
}
pair<int, int> ans[3333];
int main() {
  int n, k;
  cin >> n >> k;
  if (k == 1) {
    puts("-1");
    return 0;
  }
  if (k >= 4) {
    puts("-1");
    return 0;
  }
  if (k > n - 1) {
    puts("-1");
    return 0;
  }
  if (k == 2) {
    if (n <= 4) {
      puts("-1");
      return 0;
    }
    cout << n - 1 << endl;
    for (int i = 1; i <= n - 1; i++) printf("%d %d\n", i, i + 1);
    return 0;
  }
  if (k == 3) {
    if (n == 4) {
      cout << n - 1 << endl;
      for (int i = 1; i <= n - 1; i++) printf("%d %d\n", i, i + 1);
      return 0;
    }
    int u, v;
    if (n % 2 == 0) {
      u = n / 2 - 1, v = n / 2;
    } else {
      u = n / 2, v = n / 2 + 1;
    }
    int m = 0;
    for (int i = 1; i < n; i++) ans[m++] = pair<int, int>(i, i + 1);
    for (int i = 1; i < u - 1; i++) ans[m++] = pair<int, int>(i, u);
    for (int i = v + 2; i <= n; i++) ans[m++] = pair<int, int>(i, v);
    cout << m << endl;
    for (int i = 0; i < m; i++) printf("%d %d\n", ans[i].first, ans[i].second);
  }
  return 0;
}
