#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 5;
const int M = (int)2e6 + 6;
int main() {
  int n, k;
  cin >> n >> k;
  int root = 1;
  int leaf = 2;
  vector<pair<int, int> > ans;
  set<pair<int, int> > st;
  for (int i = 1; i <= k; i++) {
    ans.push_back({root, leaf});
    st.insert({1, leaf});
    leaf++;
  }
  int other = n - (k + 1);
  while (other--) {
    auto it = st.begin();
    int cost = it->first, v = it->second;
    ans.push_back({v, leaf});
    st.erase(it);
    st.insert({cost + 1, leaf});
    leaf++;
  }
  int d = 0;
  auto it = (--st.end());
  d += it->first;
  st.erase(it);
  it = (--st.end());
  d += it->first;
  st.erase(it);
  cout << d << endl;
  for (auto c : ans) {
    cout << c.first << " " << c.second << endl;
  }
}
