#include <bits/stdc++.h>
using namespace std;
const int N = 300200;
const int mod = 1000000007;
const int SN = 1 << 18;
long long int n;
long long int k;
int main() {
  cin >> n >> k;
  if (k == 2) {
    if (n >= 5) {
      cout << n - 1 << endl;
      for (long long 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 (long long int i = 1; i <= n - 2; i++) {
        for (long long int j = i + 1; j <= n - 2; j++) {
          cout << i << " " << j << endl;
        }
      }
      cout << n - 2 << " " << n - 1 << endl;
      cout << n - 1 << " " << n << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
