#include <bits/stdc++.h>
int main() {
  int n, k, i = 2;
  scanf("%d%d", &n, &k);
  printf("%d\n", (n - 1) / k * 2 + std::min(2, (n - 1) % k));
  while (i < k + 2) printf("1 %d\n", i++);
  while (i <= n) printf("%d %d\n", i, i - k), i++;
  return 0;
}
