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