#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int temp1 = ceil(float(n - k - 1) / k);
  int temp2 = ceil(float(n - k - 1 - temp1) / (k - 1));
  cout << temp1 + temp2 + 2 << endl;
  int st = 2;
  while (k != 0) {
    int temp = ceil(float(n - k - 1) / k);
    cout << 1 << " " << st << endl;
    st++;
    for (int i = 0; i < temp; i++, st++) cout << st - 1 << " " << st << endl;
    k--;
    n = n - temp - 1;
  }
}
