#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 4e18;
const int L = 2e5 + 7;
vector<int> g[L];
int main() {
  int n, leaf;
  cin >> n >> leaf;
  for (int i = 0; i < leaf; i++) g[i].push_back(1);
  int i = 0;
  for (int c = 2; c <= n - leaf; c++, i++) {
    g[i % leaf].push_back(c);
  }
  for (int c = n - leaf + 1; c <= n; c++, i++) g[i % leaf].push_back(c);
  cout << g[0].size() + g[1].size() - 2 << endl;
  for (int i = 0; i < leaf; i++) {
    for (unsigned int j = 1; j < g[i].size(); j++) {
      printf("%d %d\n", g[i][j - 1], g[i][j]);
    }
  }
  return 0;
}
