#include <bits/stdc++.h>
using namespace std;
int n, m, len;
int main() {
  scanf("%d%d", &n, &m);
  n -= m;
  for (int i = 2; i <= n + m; i++) {
    int x = n - (i - 1), y = m - 2, t = i / 2 - 1;
    if (1ll * y * t >= x) {
      len = i;
      break;
    }
  }
  printf("%d\n", len);
  for (int i = 1; i <= len; i++) printf("%d %d\n", i, i + 1);
  int p = len / 2 + 1, x = n - (len - 1), y = m - 2, j = len + 2;
  while (j <= n + m) {
    int pre = p, t = len / 2 - 1;
    while (t && x) {
      printf("%d %d\n", pre, j);
      pre = j;
      j++;
      x--;
      t--;
    }
    printf("%d %d\n", pre, j);
    j++;
    y--;
  }
  return 0;
}
