#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
int n, m;
void init() {
  cin >> n >> m;
  cout << ((n - 1) / m) * 2 + min(2, (n - 1) % m) << endl;
  for (int i = (2); i <= (n); ++i) cout << i << ' ' << max(1, i - m) << endl;
}
void solve() {}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  init();
  solve();
  return 0;
}
