#include <bits/stdc++.h>
using namespace std;
int nn() {
  static int x = 0;
  return ++x;
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int hub = nn();
  vector<int> in;
  for (int i = 0; i < k; ++i) in.push_back(nn());
  int pos = 0;
  int len = 2;
  vector<pair<int, int> > ans;
  while (true) {
    for (auto c : in)
      ;
    ;
    int w = nn();
    if (w > n) break;
    if (pos == 0 || pos == 1) len++;
    ans.push_back(make_pair(in[pos], w));
    in[pos] = w;
    pos++;
    if (pos >= in.size()) pos = 0;
  }
  for (auto x : in) {
    ans.emplace_back(x, hub);
  }
  printf("%d\n", len);
  for (auto x : ans) printf("%d %d\n", x.first, x.second);
}
