#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long s = n - k - 1;
  long long r = s % k;
  s = s / k;
  if (r == 1) {
    cout << 2 + s + s + 1 << endl;
  } else if (r >= 2) {
    cout << 2 + s + 1 + s + 1 << endl;
  } else {
    cout << 2 + s + s << endl;
  }
  long long count = 2;
  for (long long i = 0; i < r; i++) {
    cout << 1 << " " << count << endl;
    for (long long j = 0; j < s + 1; j++) {
      cout << count << " " << count + 1 << endl;
      count++;
    }
    count++;
  }
  for (long long i = 0; i < k - r; i++) {
    cout << 1 << " " << count << endl;
    for (long long j = 0; j < s; j++) {
      cout << count << " " << count + 1 << endl;
      count++;
    }
    count++;
  }
  return 0;
}
