#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 123;
const long long LINF = (long long)1e18 + 123;
const long double EPS = (long double)1e-8;
const long long MOD = (long long)1e9 + 7;
long long power(long long x, long long y, long long mod = MOD) {
  if (y == 0) {
    return 1;
  }
  if (y & 1) {
    return power(x, y - 1, mod) * x % mod;
  } else {
    long long tmp = power(x, y / 2, mod);
    return tmp * tmp % mod;
  }
}
void add(long long &x, long long y, long long mod = MOD) {
  x += y;
  if (x >= mod) x -= mod;
  if (x < 0) x += mod;
}
long long sum(long long x, long long y, long long mod = MOD) {
  add(x, y, mod);
  return x;
}
long long mult(long long x, long long y, long long mod = MOD) {
  return (x * y) % mod;
}
long long div(long long x, long long y, long long mod) {
  return x * power(y, mod - 2, mod);
}
template <typename A, typename B>
bool mini(A &x, const B &y) {
  if (y < x) {
    x = y;
    return true;
  }
  return false;
}
template <typename A, typename B>
bool maxi(A &x, const B &y) {
  if (y > x) {
    x = y;
    return true;
  }
  return false;
}
template <typename T>
void read(T first, T last) {
  while (first != last) {
    cin >> *(first++);
  }
}
template <typename T>
void print(T first, T last) {
  while (first != last) {
    cout << *(first++) << " ";
  }
  cout << "\n";
}
void run();
int main() {
  if (strlen("")) {
    freopen(
        ""
        ".in",
        "r", stdin);
    freopen(
        ""
        ".out",
        "w", stdout);
  }
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  run();
  return 0;
}
const int N = (int)1e6 + 123;
struct {
  long long best = LINF;
  long long a, b, x;
} ans;
void run() {
  long long n, k;
  cin >> n >> k;
  for (long long x = 1; x <= n; x++) {
    for (long long a = 0; a * x <= n - 1; a++) {
      long long rest = n - 1 - a * x;
      if (rest % (x + 1) != 0) continue;
      long long b = rest / (x + 1);
      if (a + b != k) {
        continue;
      }
      long long cur = 0;
      if (a >= 1) {
        maxi(cur, x);
      }
      if (b >= 1) {
        maxi(cur, x + 1);
      }
      if (a >= 2) {
        maxi(cur, 2 * x);
      }
      if (b >= 2) {
        maxi(cur, 2 * (x + 1));
      }
      if (a >= 1 && b >= 1) {
        maxi(cur, x + (x + 1));
      }
      if (mini(ans.best, cur)) {
        ans.a = a;
        ans.b = b;
        ans.x = x;
      }
    }
  }
  assert(ans.best != LINF);
  cout << ans.best << "\n";
  long long v = 2;
  for (auto i = 0; i < ans.a; i++) {
    cout << 1 << " " << v << "\n";
    for (auto j = 0; j < ans.x - 1; j++) {
      cout << v + j << " " << v + j + 1 << "\n";
    }
    v += ans.x;
  }
  for (auto i = 0; i < ans.b; i++) {
    cout << 1 << " " << v << "\n";
    for (auto j = 0; j < ans.x; j++) {
      cout << v + j << " " << v + j + 1 << "\n";
    }
    v += ans.x + 1;
  }
  assert(v == n + 1);
}
