#include <bits/stdc++.h>
const int N = 2e5 + 10;
int n, k, ans;
std::vector<std::pair<int, int>> v;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; i++) v.emplace_back(i, n);
  for (int i = k + 1; i < n; i++) v.emplace_back(i - k, i);
  ans = (n - 2) / k + (n - 3) / k + 2;
  printf("%d\n", ans);
  for (auto p : v) printf("%d %d\n", p.first, p.second);
  return 0;
}
