#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 8;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k, ans = 0, i, ptr = 2, last;
  cin >> n >> k;
  last = n;
  ans = (n - k - 1) / k;
  if ((n - k - 1) % k == 0) {
    ans = (ans + 1) * 2;
  } else if ((n - k - 1) % k == 1) {
    ans = (ans + 1) * 2;
    ans += 1;
  } else {
    ans = (ans + 1) * 2;
    ans += 2;
  }
  cout << ans << "\n";
  int t = k, cnt = (n - k - 1) % k, len;
  while (t--) {
    len = (n - k - 1) / k;
    if (cnt) {
      len += 1;
      cnt--;
    }
    if (len == 0)
      ptr = 1;
    else {
      cout << 1 << " " << ptr << "\n";
    }
    for (i = 0; i < len - 1; i++) {
      cout << ptr << " " << ptr + 1 << "\n";
      ptr++;
    }
    cout << ptr << " " << last << "\n";
    last--;
    ptr++;
  }
  return 0;
}
