#include <bits/stdc++.h>
long long const mod = 1e9 + 7;
using namespace std;
void solve() {
  long long n, leaf;
  cin >> n >> leaf;
  long long nonleaf = n - leaf;
  long long ans = ceil((long double)(n - leaf - 1) / (long double)leaf) + 2 +
                  ceil((long double)(n - leaf - 2) / (long double)leaf);
  cout << ans << endl;
  for (long long i = 2; i <= leaf + 1; i++) {
    cout << 1 << " " << i << endl;
  }
  for (long long i = leaf + 2; i <= n; i++) {
    cout << i << " " << i - leaf << endl;
  }
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
}
