#include <bits/stdc++.h>
using namespace std;
const long long M = 3 * (1e6) + 7, mod = 1e9 + 7;
signed main() {
  {
    long long n, k;
    cin >> n >> k;
    long long p = n - k - 1;
    long long ans = 2 * (p / k) + 2;
    if (p % k == 1)
      ans++;
    else if (p % k > 1)
      ans += 2;
    cout << ans << "\n";
    long long x = p % k, num = k + 2;
    for (long long i = 1; i <= k; i++) {
      long long cnt = p / k, c = i;
      if (x > 0) {
        cnt++;
        x--;
      }
      for (long long j = 1; j <= cnt; j++) {
        cout << c << " " << num << "\n";
        c = num;
        num++;
      }
      cout << c << " " << k + 1 << "\n";
    }
  }
  return 0;
}
