#include <bits/stdc++.h>
using namespace std;
int con[202020];
vector<pair<int, int> > ans;
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 2; i <= k + 1; i++) {
    ans.push_back(make_pair(1, i));
    con[i] = 1;
  }
  for (int i = k + 2; i <= n; i++) {
    ans.push_back(make_pair(i - k, i));
    con[i] = con[i - k] + 1;
  }
  sort(con + 1, con + n + 1);
  cout << con[n] + con[n - 1] << '\n';
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].first << ' ' << ans[i].second << '\n';
  }
}
