#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> edges;
  int a = K + 1, n = N - K - 1;
  vector<int> deps;
  for (int i = 0; i < K; i++) {
    int dep = n / (K - i);
    if (n % (K - i) != 0) dep++;
    deps.push_back(dep + 1);
    int last = N;
    for (int j = 0; j < dep; j++) {
      edges.push_back(make_pair(last, a));
      last = a;
      a++;
    }
    n -= dep;
    edges.push_back(make_pair(last, i + 1));
  }
  sort(begin(deps), end(deps));
  cout << deps[K - 1] + deps[K - 2] << "\n";
  for (int i = 0; i < (int)edges.size(); i++) {
    cout << edges[i].first << " " << edges[i].second << "\n";
  }
}
