#include <bits/stdc++.h>
using namespace std;
const int N = 200004;
int n, k;
vector<int> g[N];
vector<pair<int, int> > v;
int main() {
  scanf("%d %d", &n, &k);
  int p = k + 1;
  for (; p < n;) {
    for (int i = 1; i <= k && p < n; i++, p++) g[i].push_back(p);
  }
  for (int i = 1; i <= k; i++) {
    if (g[i].empty())
      v.push_back(pair<int, int>(i, n));
    else {
      v.push_back(pair<int, int>(i, g[i][0]));
      for (int j = 1; j < g[i].size(); j++)
        v.push_back(pair<int, int>(g[i][j], g[i][j - 1]));
      v.push_back(pair<int, int>(n, g[i].back()));
    }
  }
  printf("%d\n", g[1].size() + g[2].size() + 2);
  for (int i = 0; i < v.size(); i++) printf("%d %d\n", v[i].first, v[i].second);
}
