#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int mod = 1000000007;
struct node {
  int x, y;
  node() {}
  node(int xx, int yy) : x(xx), y(yy) {}
  bool operator<(const node a) const {
    if (x == a.x) return y < a.y;
    return x < a.x;
  }
};
int a[1005];
int b[1005];
int c[1005];
int d[1005];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
char s[1005];
bool vis[1005];
int n, m;
int ans;
int main() {
  int tt, ca = 1;
  int p, q;
  scanf("%d %d", &n, &m);
  n--;
  p = n / m;
  q = n - m * p;
  ans = p * 2;
  if (q == 1) ans += 1;
  if (q >= 2) ans += 2;
  printf("%d\n", ans);
  int a = 2;
  for (int i = 0; i < m; i++) {
    printf("1 %d\n", a);
    for (int i = 1; i < p + (q > 0); i++) {
      printf("%d %d\n", a, a + 1);
      a++;
    }
    a++;
    q--;
  }
  return 0;
}
