#include <bits/stdc++.h>
using namespace std;
const int M = 200010;
vector<int> A[M];
int visited[M];
queue<int> q;
int MAXX = 0;
void dfs(int u, int l) {
  MAXX = max(MAXX, l);
  visited[u] = 1;
  for (int v : A[u]) {
    if (!visited[v]) dfs(v, l + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, f, i, j, k;
  scanf("%d%d", &n, &f);
  for (i = 2; i <= f + 1; i++) {
    A[1].push_back(i);
    A[i].push_back(1);
    q.push(i);
  }
  while (i <= n && !q.empty()) {
    int u = q.front();
    q.pop();
    A[u].push_back(i);
    A[i].push_back(u);
    q.push(i);
    i++;
  }
  dfs(n, 0);
  printf("%d\n", MAXX);
  for (i = 1; i <= n; i++) {
    for (int j : A[i]) {
      if (i < j) printf("%d %d\n", i, j);
    }
  }
  return 0;
}
