#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <cstdio>
#include <cassert>
#include <stack>

#include "testlib.h"

using namespace std;

typedef long long ll;
typedef long double ld;

#ifdef WIN32
	#define LLD "%I64d"
#else
	#define LLD "%lld"
#endif

int main(int argc, char* argv[])
{
    registerGen(argc, argv, 1);
    
    int n = atoi(argv[1]);
    int max_diff = atoi(argv[2]);
	vector<int> cnt(n);
    
	printf("%d\n", n);
	for (int i = 1; i < n; i++)
    {
        int a = i;
        int b = rnd.next(max(0, i - max_diff), i - 1);
		while (cnt[b] >= 2)
			b = rnd.next(max(0, i - max_diff), i - 1);
		++cnt[b];
        printf("%d %d\n", a + 1, b + 1);
    }
	return 0;
}
