#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
  node();
  node(int a, int b) {
    x = a;
    y = b;
  }
};
vector<node> g;
int vis[1005];
int main() {
  int n, k;
  cin >> n >> k;
  if (k > 3 || k == 1 || n < 4 || (n == 4 && k == 2)) {
    cout << -1 << endl;
    return 0;
  }
  if (k == 2) {
    cout << n - 1 << endl;
    for (int i = 1; i < n; i++) {
      cout << i << " " << i + 1 << endl;
    }
  } else {
    for (int i = 1; i < n; i++) {
      g.push_back(node(i, i + 1));
    }
    for (int i = 5; i <= n; i++) {
      if (i != 5) g.push_back(node(1, i));
      g.push_back(node(3, i));
    }
    cout << g.size() << endl;
    for (int i = 0; i < g.size(); i++) {
      cout << g[i].x << " " << g[i].y << endl;
    }
  }
  return 0;
}
