#include <bits/stdc++.h>
using namespace std;
int n, k;
const int Size = 2e3 + 5;
vector<string> ans;
int main() {
  cin >> n >> k;
  for (int i = 0; i < k; ++i) {
    ans.push_back("1 " + to_string(i + 2));
  }
  int i = 1, j = 0, num = 2;
  while (num != n) {
    if (num + k <= n) ans.push_back(to_string(num) + " " + to_string(num + k));
    num++;
    if (j == k - 1) {
      j = 0;
      i += 1;
    } else
      j++;
  }
  int dis = j == 0 ? i + (i - 1) : 2 * i;
  cout << dis << '\n';
  for (string an : ans) cout << an << '\n';
  return 0;
}
