#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  if (k == 1 || k > 3 || (n == 4 && k == 2) || n < 4) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 4 && k == 3) {
    cout << "3\n1 2\n 3 4\n 2 3" << endl;
    return 0;
  }
  if (k == 2) {
    vector<pair<int, int> > res;
    for (int v = 0; v < n - 1; ++v) {
      res.push_back({v, v + 1});
    }
    cout << res.size() << "\n";
    for (auto p : res) {
      cout << p.first + 1 << " " << p.second + 1 << "\n";
    }
  } else {
    vector<pair<int, int> > res;
    for (int v = 0; v < n - 1; ++v) {
      res.push_back({v, v + 1});
    }
    for (int v = 2; v < n - 1; ++v) {
      res.push_back({0, v});
    }
    cout << res.size() << "\n";
    for (auto p : res) {
      cout << p.first + 1 << " " << p.second + 1 << "\n";
    }
  }
}
