#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000000 + 10;
const int mod = (int)1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long LINF = (1LL << 60);
const double PI = acos(-1.0);
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  int a = (n - 1) / k, b = (n - 1) % k;
  cout << a * 2 + min(2, b) << endl;
  for (int i = 2; i <= min(k + 1, n); i++) cout << 1 << " " << i << endl;
  int u = 2, v = k + 2;
  while (v <= n) {
    cout << u << " " << v << endl;
    u++;
    v++;
  }
  return 0;
}
