#include <bits/stdc++.h>
using namespace std;
int II() {
  int q;
  scanf("%d", &q);
  return q;
}
long long LII() {
  long long q;
  scanf("%lld", &q);
  return q;
}
void solve() {
  int N, K;
  cin >> N >> K;
  vector<int> v[K];
  for (int i = 2; i <= N; i += K) {
    for (int j = i, k = 0; j < (i + K) && j <= N; j++, k++) {
      v[k].push_back(j);
    }
  }
  cout << v[0].size() + v[1].size() << endl;
  for (int i = 0; i < K; i++) {
    cout << 1 << " " << v[i].front() << endl;
    for (int j = 1; j < v[i].size(); j++) {
      cout << v[i][j - 1] << " " << v[i][j] << endl;
    }
  }
}
int32_t main() {
  int tt;
  tt = 1;
  int cas = 1;
  while (tt--) {
    solve();
  }
}
