#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long INF = 1e9;
const int N = 2100031;
vector<pair<int, int> > edges;
int n;
int ar[100][100];
int get_d() {
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        ar[i][j] = min(ar[i][j], ar[i][k] + ar[k][j]);
      }
    }
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      res = max(res, ar[i][j]);
    }
  }
  if (res > 100) res = -1;
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  int k;
  cin >> n;
  cin >> k;
  if (k > 3) {
    cout << -1 << endl;
    return 0;
  }
  if (k == 3) {
    if (n < 4) {
      cout << -1 << endl;
      return 0;
    }
    cout << n - 1 << endl;
    for (int i = 2; i <= n; i++) {
      if (i != 3) cout << 1 << " " << i << endl;
    }
    cout << 2 << " " << 3 << endl;
    return 0;
  }
  if (k == 1) {
    cout << -1 << endl;
    return 0;
  }
  if (n < 5) {
    cout << -1 << endl;
    return 0;
  }
  cout << n - 1 << endl;
  for (int i = 1; i < n; i++) {
    cout << i << " " << i + 1 << endl;
  }
  cin.get();
  cin.get();
  return 0;
}
