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