#include <bits/stdc++.h>
#pragma comment(linker, "/stack:16777216")
using namespace std;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const long long LINF = INF * (long long)INF;
const int MOD = 1000 * 1000 * 1000 + 7;
const int X = 1048576;
struct Tree {
  int a[2 * X];
  void add(long long num) {
    num += X;
    while (num) {
      a[num]++;
      num /= 2;
    }
  }
  long long s(long long l, long long r) {
    l += X;
    r += X;
    long long res = 0;
    while (l <= r) {
      if (l % 2 == 1) {
        res += a[l];
        l++;
      }
      if (r % 2 == 0) {
        res += a[r];
        r--;
      }
      l /= 2;
      r /= 2;
    }
    return res;
  }
} T;
int main() {
  int n, k;
  cin >> n >> k;
  if (k == 1 || k > 3 || n < 4) {
    cout << -1;
    return 0;
  }
  if (k == 3) {
    if (n == 4) {
      cout << n - 1 << "\n";
      for (int i = (0); i < (n - 1); i++) cout << i + 1 << " " << i + 2 << "\n";
    } else {
      cout << n - 1 << endl;
      for (int i = (2); i < (n); i++) cout << "1 " << i + 1 << "\n";
      cout << "2 3\n";
    }
  }
  if (k == 2) {
    if (n == 4)
      cout << -1;
    else {
      cout << n - 1 << "\n";
      for (int i = (0); i < (n - 1); i++) cout << i + 1 << " " << i + 2 << "\n";
    }
  }
}
