#include <bits/stdc++.h>
using namespace std;
int n, m, cnt, len;
int a[200005];
struct node {
  int l, r;
} ans[200005];
void addedge(int l, int r) {
  ans[cnt].l = l;
  ans[cnt].r = r;
  cnt++;
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    cnt = 0;
    len = 0;
    int flag = 0;
    int need = n - m - 1;
    int now = 2;
    int last = min(need, m);
    for (int i = 1; i <= last; i++) {
      addedge(1, now);
      a[i] = now;
      now++;
      flag++;
      if (flag >= 2) flag = 2;
    }
    len += flag;
    while (now <= (n - m)) {
      flag = 0;
      for (int i = 1; i <= last; i++) {
        if (now <= (n - m)) {
          addedge(a[i], now);
          a[i] = now;
          now++;
          flag++;
          if (flag >= 2) flag = 2;
        } else
          break;
      }
      len += flag;
    }
    for (int i = 1; i <= last; i++) {
      addedge(a[i], now);
      now++;
    }
    while (now <= n) {
      addedge(1, now);
      now++;
    }
    printf("%d\n", len + 2);
    for (int i = 0; i < cnt; i++) printf("%d %d\n", ans[i].l, ans[i].r);
  }
  return 0;
}
