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