#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
long long int n, k;
int main() {
  cin >> n >> k;
  long long int temp = (n - 1) / (k);
  long long int temp1 = (n - 1) % (k);
  long long int ans = 2 * temp + min(temp1, (long long)2);
  cout << ans << endl;
  for (int i = 2; i <= min(k + 1, n); i++) cout << 1 << " " << i << endl;
  for (int i = k + 2; i <= n; i++) cout << i - k << " " << i << endl;
  return 0;
}
