#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to, next;
} f[200010 << 1];
int n, k, d[200010], head[200010], l = 0;
void Dfs(int u, int fa) {
  d[u] = d[fa] + 1;
  for (int i = head[u]; i; i = f[i].next)
    if (f[i].to != fa) Dfs(f[i].to, u);
}
int main() {
  cin >> n >> k;
  for (int i = 2; i <= n; i++) {
    int v = (i <= k + 1) ? 1 : i - k;
    ({
      f[++l] = (Edge){v, head[i]};
      head[i] = l;
    });
    ({
      f[++l] = (Edge){i, head[v]};
      head[v] = l;
    });
  }
  Dfs(n, 0);
  int ans = 0;
  for (int i = 1; i <= n; i++) ans = max(ans, d[i]);
  cout << ans - 1 << endl;
  for (int i = 2; i <= n; i++) {
    int v = (i <= k + 1) ? 1 : i - k;
    printf("%d %d\n", i, v);
  }
  return 0;
}
