#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:67108864")
using namespace std;
const int MOD = 1000000007;
const long long INF = 1e18;
const int DIS = 500000000;
const long double EPS = 1e-6;
const int HASH_POW = 29;
const long double PI = acos(-1.0);
mt19937_64 rnd(1);
double workTime() { return double(clock()) / CLOCKS_PER_SEC; }
void my_return(int code) { exit(code); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  scanf("%d %d", &n, &k);
  if (n <= 3)
    printf("-1\n");
  else if (n == 4) {
    if (k <= 2)
      printf("-1\n");
    else
      printf("3\n1 2\n2 3\n3 4\n");
  } else if (k == 2) {
    printf("%d\n", n - 1);
    for (int i = 1; i < n; ++i) printf("%d %d\n", i, i + 1);
  } else if (k == 3) {
    vector<pair<int, int> > edges;
    edges.push_back(make_pair(1, 2));
    edges.push_back(make_pair(2, 3));
    edges.push_back(make_pair(3, 4));
    for (int i = 5; i <= n; ++i) {
      edges.push_back(make_pair(i, 2));
      edges.push_back(make_pair(i, 3));
    }
    printf("%d\n", edges.size());
    for (int i = 0; i < edges.size(); ++i)
      printf("%d %d\n", edges[i].first, edges[i].second);
  } else
    printf("-1\n");
  my_return(0);
}
