#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
const int INF = 1e9 + 7;
const long double EPS = 1e-13;
const long double PI = 3.14159265359;
int main() {
  int n, k;
  cin >> n >> k;
  if (k == 2) {
    if (n >= 5) {
      cout << n - 1 << endl;
      for (int i = 1; i < n; i++) cout << i << ' ' << i + 1 << endl;
      return 0;
    }
  }
  if (k == 3) {
    if (n >= 4) {
      cout << (n - 2) * (n - 3) / 2 + 2 << endl;
      for (int i = 1; i <= n - 2; i++) {
        for (int j = i + 1; j <= n - 2; j++) {
          cout << i << ' ' << j << endl;
        }
      }
      cout << n - 1 << ' ' << n - 2 << endl;
      cout << n - 1 << ' ' << n << endl;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
