#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 7;
int main() {
  long long n, k;
  cin >> n >> k;
  if (n - 2 - k >= 0 && !((n - 2 - k) % k)) {
    cout << ((n - k - 1) / k) * 2 + 3 << endl;
  } else {
    long long tmp = (n - k - 1) / k + ((n - k - 1) % k > 0);
    cout << tmp * 2 + 2 << endl;
  }
  long long cur = 0;
  for (long long i = 1; i <= k; i++) {
    cout << "1 " << i + 1 << endl;
  }
  for (long long i = k + 1; i < n; i++) {
    cout << i - k + 1 << " " << i + 1 << endl;
  }
  cin >> n;
  return 0;
}
