#include <bits/stdc++.h>
using namespace std;
const int MAX_N = (int)1e6 + 500;
const int mod = (int)1e9 + 7;
int n, k;
vector<pair<int, int> > q;
int d[505][505], d2[505][505];
void solve(int mask) {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      d[i][j] = (i == j ? 0 : mod), d2[i][j] = (i == j ? 0 : mod);
  for (int i = 0; i < int((q).size()); i++) {
    if (mask & (1 << i))
      d[q[i].first][q[i].second] = d[q[i].second][q[i].first] = 1;
    else
      d2[q[i].first][q[i].second] = d2[q[i].second][q[i].first] = 1;
  }
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);
  int a = -1, b = -1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) a = max(a, d[i][j]), b = max(b, d2[i][j]);
  if (a == mod || b == mod) return;
  int val = min(a, b);
  if (val == k) {
    cout << "-----\n";
    for (int i = 0; i < int((q).size()); i++)
      if (mask & (1 << i)) cout << q[i].first << ' ' << q[i].second << endl;
    cout << endl;
  }
}
int main() {
  ios_base ::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
  cin >> n >> k;
  if (k != 2 && k != 3) {
    cout << "-1";
    return 0;
  }
  if (n < 4) {
    cout << "-1";
    return 0;
  }
  if (n == 4 && k == 2) {
    cout << "-1";
    return 0;
  }
  cout << n - 1 << endl;
  if (k == 2) {
    for (int i = 1; i < n; i++) cout << i << ' ' << i + 1 << endl;
    return 0;
  }
  cout << "1 2\n";
  cout << "2 3\n";
  for (int i = 4; i <= n; i++) cout << "1 " << i << endl;
  return 0;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) q.push_back(make_pair(i, j));
  for (int mask = 0; mask < (1LL << int((q).size())); mask++) solve(mask);
  return 0;
}
