#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 1;
const int M = 1e9 + 7;
const double eps = 1e-6;
int n, k;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  int a = (n - 1) / k * 2 + min(2, (n - 1) % k);
  cout << a << endl;
  for (int i = (2); i <= (n); i++) {
    cout << max(i - k, 1) << " " << i << endl;
  }
}
