#include <bits/stdc++.h>
using namespace std;
template <class T, class S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
  return os << "(" << v.first << ", " << v.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "[";
  for (int i = int(0); i <= int((static_cast<int>((v).size())) - 1); ++i) {
    if (i) os << ", ";
    os << v[i];
  }
  return os << "]";
}
template <class T>
bool setmax(T& _a, T _b) {
  if (_a < _b) {
    _a = _b;
    return true;
  }
  return false;
}
template <class T>
bool setmin(T& _a, T _b) {
  if (_b < _a) {
    _a = _b;
    return true;
  }
  return false;
}
template <class T>
T gcd(T _a, T _b) {
  return _b == 0 ? _a : gcd(_b, _a % _b);
}
int main() {
  int n, k;
  cin >> n >> k;
  if (n <= 3 || (n == 4 && k == 2) || (k != 2 && k != 3)) {
    printf("-1\n");
  } else {
    if (k == 2) {
      printf("%d\n", 3 + (n - 4) * 2);
      printf("1 2\n");
      printf("2 3\n");
      printf("3 4\n");
      for (int i = int(5); i <= int(n); ++i) {
        printf("%d 1\n", i);
        printf("%d 4\n", i);
      }
    } else {
      printf("%d\n", 1 + (n - 3) * 2);
      printf("1 2\n");
      for (int i = int(4); i <= int(n); ++i) {
        printf("%d 2\n", i);
        printf("%d 3\n", i);
      }
    }
  }
  return 0;
}
