#include <bits/stdc++.h>
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n, k;
  std::cin >> n >> k;
  int p = (n - 1) % k;
  int x = (n - 1) / k;
  int long_way = 2 * x;
  if (p == 1) {
    ++long_way;
  }
  if (p > 1) {
    long_way += 2;
  }
  std::cout << long_way << "\n";
  for (int i = 2; i <= k + 1; ++i) {
    std::cout << 1 << " " << i << "\n";
  }
  for (int i = 2; i <= n; ++i) {
    int r = i + k;
    if (r > n) {
      break;
    }
    std::cout << i << " " << r << '\n';
  }
  return 0;
}
