#include <bits/stdc++.h>
using namespace std;
const int M = 2e6 + 5, INF = 0x3f3f3f3f, mod = 1e9 + 7;
const int HASH = 1e4 + 7, STATE = 1e6 + 5;
vector<pair<int, int> > ans;
void getmax(int &a, int &b, int c) {
  if (c >= a) {
    b = a;
    a = c;
  } else if (c > b) {
    b = c;
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  queue<pair<int, int> > Q;
  int maxx = 0, maxx1 = 0;
  for (int j = 2; j <= m + 1; j++) {
    ans.push_back({1, j});
    Q.push({j, 1});
    getmax(maxx, maxx1, 1);
  }
  for (int j = m + 2; j <= n; j++) {
    int now = Q.front().first, step = Q.front().second;
    ans.push_back({now, j});
    Q.pop();
    Q.push({j, step + 1});
    getmax(maxx, maxx1, step + 1);
  }
  printf("%d\n", maxx + maxx1);
  for (auto x : ans) {
    printf("%d %d\n", x.first, x.second);
  }
  return 0;
}
