#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  int maxlevel = 0, issingle = true;
  if ((n - 1) % k == 0) {
    maxlevel = (n - 1) / k;
    issingle = false;
  } else {
    if ((n - 1) % k == 1) {
      maxlevel = (n - 1) / k + 1;
    } else {
      maxlevel = (n - 1) / k + 1;
      issingle = false;
    }
  }
  if (issingle == true) {
    printf("%d\n", 2 * maxlevel - 1);
  } else
    printf("%d\n", 2 * maxlevel);
  for (int i = 2; i <= n; i++) {
    if (i <= k + 1) {
      printf("1 %d\n", i);
    } else {
      printf("%d %d\n", i - k, i);
    }
  }
  return 0;
}
