#include <bits/stdc++.h>
using namespace std;
int n, m, k, x, y, sum, cnt, ans;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  m = (n - 1) / k;
  int r = (n - 1) % k;
  if (r == 0)
    ans = 2 * m;
  else if (r == 1)
    ans = 2 * m + 1;
  else
    ans = 2 * m + 2;
  cout << ans << endl;
  cnt = 1;
  for (int i = (1); i <= (k); i++) {
    if (i <= r) {
      cnt++;
      cout << "1 " << cnt << endl;
      for (int j = (2); j <= (m + 1); j++) {
        cnt++;
        cout << cnt - 1 << ' ' << cnt << endl;
      }
    } else {
      cnt++;
      cout << "1 " << cnt << endl;
      for (int j = (2); j <= (m); j++) {
        cnt++;
        cout << cnt - 1 << ' ' << cnt << endl;
      }
    }
  }
  return 0;
}
