#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 6;
int N, K, lev[MAX];
vector<pair<int, int> > arr;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> N >> K;
  for (int i = 1; i <= K; ++i) {
    arr.push_back({1, i + 1});
    lev[i + 1] = 1;
  }
  int cur = K + 2;
  int idx = 0;
  while (true) {
    if (cur > N)
      break;
    else {
      auto it = arr[idx];
      arr.push_back({it.second, cur});
      lev[cur] = lev[it.second] + 1;
      ++cur;
      ++idx;
    }
  }
  int f = 0, s = 0;
  for (int i = 1; i <= N; ++i) {
    if (lev[i] >= f) {
      s = f;
      f = lev[i];
    } else if (lev[i] > s)
      s = lev[i];
  }
  if (K > 1)
    cout << f + s << endl;
  else
    cout << f << endl;
  for (auto it : arr) cout << it.first << ' ' << it.second << endl;
}
