#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using std::abs;
using std::cerr;
using std::cin;
using std::cout;
using std::map;
using std::max;
using std::min;
using std::pair;
using std::set;
using std::string;
using std::swap;
using std::vector;
using ll = long long;
using uint = unsigned int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
void err(vector<string>::iterator it, T a) {
  cerr << it->substr((*it)[0] == ' ') << " = " << a << '\n';
}
template <typename T, typename... Ts>
void err(vector<string>::iterator it, T a, Ts... as) {
  cerr << it->substr((*it)[0] == ' ') << " = " << a << ", ";
  err(++it, as...);
}
struct init {
  init() {
    cin.tie(0);
    std::iostream::sync_with_stdio(0);
    cout << std::fixed << std::setprecision(10);
    cerr << std::fixed << std::setprecision(10);
    using namespace std::chrono;
    srand(duration_cast<nanoseconds>(
              high_resolution_clock::now().time_since_epoch())
              .count());
  }
  ~init() {
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
  }
} init;
void no() {
  cout << "-1\n";
  exit(0);
}
int main() {
  int n, k;
  cin >> n >> k;
  if (n < 4 || k > 3 || k == 1 || n == 4 && k == 2)
    no();
  else if (k == 2) {
    cout << n - 1 << '\n';
    for (int i = 1; i < n; ++i) cout << i << ' ' << i + 1 << '\n';
  } else {
    cout << (n - 3) * 2 + 1 << '\n';
    cout << "1 3\n";
    for (int i = 4; i <= n; ++i) {
      cout << i << " 1\n";
      cout << i << " 2\n";
    }
  }
  return 0;
}
