#include <bits/stdc++.h>
using namespace std;
bool compare1(pair<long long, long long> a1, pair<long long, long long> a2) {
  double aa = ((double)a1.first) / a1.second;
  double bb = ((double)a2.first) / a2.second;
  return aa > bb;
}
long long min(long long a, long long b) {
  if (a > b) return b;
  return a;
}
long long max(long long a, long long b) {
  if (a > b) return a;
  return b;
}
long long hashs(string a) {
  long long k = 27;
  long long value = 0;
  for (long long i = 0; i < a.length(); i++) {
    value = ((value * k + (a[i] - 'a' + 1))) % 10000000000007;
  }
  return value;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  deque<int> arr;
  for (int i = 1; i <= k; i++) {
    arr.push_back(i);
  }
  int count = 2;
  vector<pair<int, int>> ans;
  int mark = k + 1;
  while (mark < n) {
    if (n - mark == 1)
      count += 1;
    else
      count += 2;
    int pp = mark + k;
    while (mark < n && mark < pp) {
      ans.push_back(make_pair(mark, arr.back()));
      arr.pop_back();
      arr.push_front(mark++);
    }
  }
  for (int i = 0; i < arr.size(); i++) {
    ans.push_back(make_pair(n, arr[i]));
  }
  cout << count << "\n";
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first << " " << ans[i].second << "\n";
}
