#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1073741824")
using namespace std;
int main() {
#pragma warning(disable : 4996)
  int n, k;
  scanf("%d%d", &n, &k);
  int c = (n - 1) / k, ex = n - 1 - k * c;
  printf("%d\n", c * 2 + (ex ? (ex > 1 ? 2 : 1) : 0));
  int nn = 1;
  for (int i = 0; i < k; i++) {
    printf("1 %d\n", ++nn);
    for (int j = 0; j < c + (ex > 0 ? 0 : -1); j++, nn++)
      printf("%d %d\n", nn, nn + 1);
    ex--;
  }
  return 0;
}
