#include <bits/stdc++.h>
using namespace std;
int n;
int k;
int main() {
  cin >> n >> k;
  int l = (n - 1) / k * 2 + ((n - 1) % k != 0) + ((n - 1) % k >= 2);
  cout << l << endl;
  for (int i = 1; i < n; i++) {
    if (i <= k)
      cout << i + 1 << ' ' << 1 << endl;
    else
      cout << i + 1 << ' ' << i + 1 - k << endl;
  }
  return 0;
}
