#include <bits/stdc++.h>
using namespace std;
int v[212345];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < k; ++i) v[i] += (n - 1) / k;
  for (int i = 0; i < (n - 1) % k; ++i) v[i]++;
  printf("%d\n", v[0] + v[1]);
  for (int i = 1; i <= k; ++i) printf("%d %d\n", 1, i + 1);
  int x = k + 2;
  for (int i = 0; i < k; ++i) {
    for (int j = 1; j < v[i]; ++j) {
      if (j == 1)
        printf("%d %d\n", i + 2, x);
      else {
        printf("%d %d\n", x, x + 1);
        x++;
      }
    }
    x++;
  }
  return 0;
}
