#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 102;
const int maxM = (int)1e6 + 100;
const int mod = (int)1e9 + 7;
const int maxlog = (int)20;
int n, k, lvl[maxn];
int main() {
  cin >> n >> k;
  for (int i = n - 1; i >= 1; i--) {
    int to = i, v = min(n, i + k);
    lvl[to] = lvl[v] + 1;
  }
  sort(lvl + 1, lvl + k + 1);
  cout << lvl[k] + lvl[k - 1] << endl;
  for (int i = 1; i < n; i++) cout << i << " " << min(n, i + k) << endl;
}
