#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  if (k == 1 || k > 3) {
    cout << -1 << '\n';
    return 0;
  }
  if (k == 3) {
    if (n < 4) {
      cout << -1 << '\n';
    } else {
      vector<pair<int, int> > e;
      e.push_back(make_pair(1, 2));
      e.push_back(make_pair(2, 3));
      e.push_back(make_pair(3, 4));
      for (int i = 5; i <= n; i++) {
        e.push_back(make_pair(2, i));
        e.push_back(make_pair(3, i));
      }
      cout << e.size() << '\n';
      for (int i = 0; i < e.size(); i++)
        cout << e[i].first << " " << e[i].second << '\n';
    }
  }
  if (k == 2) {
    if (n < 5) {
      cout << -1 << '\n';
    } else {
      vector<pair<int, int> > e;
      e.push_back(make_pair(1, 2));
      e.push_back(make_pair(2, 3));
      e.push_back(make_pair(3, 4));
      e.push_back(make_pair(4, 5));
      for (int i = 6; i <= n; i++) {
        e.push_back(make_pair(i, i - 1));
      }
      cout << e.size() << '\n';
      for (int i = 0; i < e.size(); i++)
        cout << e[i].first << " " << e[i].second << '\n';
    }
  }
  return 0;
}
