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