#include <bits/stdc++.h>
using namespace std;
const long long N = 500010;
inline long long read() {
  long long s = 0, w = 1;
  register char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
  return s * w;
}
long long n, k, mx;
signed main() {
  n = read(), k = read();
  mx = (n - 1) / k * 2;
  if ((n - 1) % k) {
    if ((n - 1) % k == 1)
      mx++;
    else
      mx += 2;
  }
  printf("%lld\n", mx);
  for (register long long i = 2; i <= k + 1; i++) printf("%lld %lld\n", 1ll, i);
  for (register long long i = k + 2; i <= n; i++)
    printf("%lld %lld\n", i, i - k);
  return 0;
}
