#include <bits/stdc++.h>
using namespace std;
int n, k;
int main() {
  scanf("%d%d", &n, &k);
  int ans = (n - 1 + k - 1) / k;
  if ((n - 1) % k == 1)
    printf("%d\n", 2 * ans - 1);
  else
    printf("%d\n", 2 * 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);
}
