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