#include <bits/stdc++.h>
using namespace std;
int const INF = 100 + (int)1e9;
long long const INFL = 100 + (long long)1e18;
long double const PI = 3.141592653589793238462643L;
mt19937 tw(960172);
bool is_prime(long long x) {
  for (long long y = 2; y * y <= x; ++y)
    if (x % y == 0) return 0;
  return x > 1;
}
long long rnd(long long x, long long y) {
  static uniform_int_distribution<long long> d;
  return d(tw) % (y - x + 1) + x;
}
long long sqr(int a) { return (long long)a * a; }
template <class T>
T sqr(T const& a) {
  return a * a;
}
long long gcd(long long a, long long b) {
  while (b > 0) {
    long long t = a % b;
    a = b;
    b = t;
  }
  return a;
}
void solve() {
  int n, k;
  cin >> n >> k;
  if (n <= 3 || k == 1 || k > 3 || (n == 4 && k == 2)) {
    cout << -1 << '\n';
    return;
  }
  vector<pair<int, int>> edges;
  if (k == 2) {
    for (int i = 1; i < n; ++i) edges.emplace_back(i, i + 1);
  } else {
    edges.emplace_back(1, 2);
    edges.emplace_back(2, 3);
    edges.emplace_back(3, 4);
    for (int i = 5; i <= n; ++i) {
      edges.emplace_back(i, 1);
      edges.emplace_back(i, 3);
      if (i > 5) {
        edges.emplace_back(i, i - 1);
        if (i > 6) edges.emplace_back(i, 5);
      }
    }
  }
  cout << edges.size() << '\n';
  for (auto e : edges) cout << e.first << ' ' << e.second << '\n';
}
int main() {
  cout << setprecision(15) << fixed;
  int tcnt = 1;
  for (int test = 1; test <= tcnt; ++test) solve();
}
