#include <bits/stdc++.h>
using namespace std;
int mypowerfun(int arr, int b) {
  if (b == 0) return 1;
  if (b == 1) return arr;
  int x = mypowerfun(arr, b / 2);
  if (b % 2 == 0)
    return x * x;
  else
    return x * x * arr;
}
void pri_arr(int arr[], int n) {
  int i;
  for (i = 0; i < n; i++) printf("%d ", arr[i]);
  printf("\n");
}
void pri_vec(vector<int> a, int n) {
  for (std::vector<int>::iterator it = a.begin(); it != a.end(); ++it)
    std::cout << *it;
  std::cout << '\n';
}
int mygcd(int arr, int b) {
  if (b != 0)
    return mygcd(b, arr % b);
  else
    return arr;
}
int xxx, yyy;
int store[105][105];
void fun1() {
  if (xxx - yyy == 1)
    cout << 2 << "\n";
  else if (xxx - yyy == 2)
    cout << 3 << "\n";
  else
    cout << 4 << "\n";
}
void fun3();
int fun2(int xxx, int yyy, bool gett);
int main() {
  cin >> xxx >> yyy;
  cout << fun2(xxx, yyy, 0) << "\n";
  fun2(xxx, yyy, 1);
  return 0;
}
int fun2(int xxx, int yyy, bool gett) {
  if (!gett) {
    if (xxx == 2 && yyy == 2) return 1;
    if (xxx == 1 && yyy == 1) return 0;
    if (xxx == yyy + 1) return 2;
    if (xxx - yyy <= yyy) {
      if (xxx - yyy == 2)
        return 2 + fun2(xxx - yyy, xxx - yyy, 0);
      else
        return 2 + fun2(xxx - yyy, xxx - yyy - 1, 0);
    } else
      return 2 + fun2(xxx - yyy, yyy, 0);
  }
  if (xxx == 2 && yyy == 2) {
    cout << "1 2"
         << "\n";
    return 0;
  } else if (xxx == 1 && yyy == 1)
    return 0;
  if (xxx == yyy + 1) {
    for (int i = 2; i <= xxx; i++) cout << "1 " << i << "\n";
    return 0;
  }
  if (xxx - yyy <= yyy) {
    if (xxx - yyy == 2) {
      fun2(2, 2, 1);
      cout << "1 3\n";
      for (int i = 4; i <= xxx; i++) cout << "2 " << i << "\n";
      return 0;
    }
    fun2(xxx - yyy, xxx - yyy - 1, 1);
    int val2 = xxx - yyy + 1;
    int val1 = 2;
    for (val1 = 2; val1 <= xxx - yyy; val1++) {
      cout << val1 << " " << val2 << "\n";
      val2++;
    }
    while (val2 <= xxx) {
      cout << "2 " << val2 << "\n";
      val2++;
    }
  } else {
    fun2(xxx - yyy, yyy, 1);
    for (int i = xxx - yyy + 1; i <= xxx; i++) {
      cout << i - yyy << " " << i << "\n";
    }
    return 0;
  }
}
void fun3() {
  store[1][1] = 0;
  store[2][1] = 1 << 30;
  store[2][2] = 1;
  for (int i = 3; i <= 100; i++) {
    store[i][1] = 1 << 30;
    for (int j = i; j <= 100; j++) store[i][j] = 1 << 30;
    for (int j = 2; j < i; j++) {
      int valuee = 1 << 30;
      for (int k = 1; k <= i - j && k <= j; k++)
        valuee = min(valuee, store[i - j][k]);
      store[i][j] = valuee + 2;
    }
  }
  for (int i = 1; i <= 100; i++, cout << "\n") {
    for (int j = 1; j <= i; j++)
      cout << (store[i][j] == (1 << 30) ? -1 : store[i][j]) << " ";
  }
}
