//* Problem  : 1064 - Binary Search
//* Contest  : acm.timus.ru
//* Type     : Solution
//* Date     : 2008.06.28
//* Author   : alt
//* Language : C++
//* Compiler : Microsoft Visual C++ 6.0

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

int k, m, res, r[10010], rr[10000][2];

int bs(int l, int r, int k, int m)
{
	if (!m) return 0;
	if (l > r) return 0;
	int mm = (l + r) / 2;
	if (k == mm) return m == 1;
	if (k > mm) return bs(mm + 1, r, k, m - 1);
	if (k < mm) return bs(l, mm - 1, k, m - 1);
	return 0;
}

void solve()
{
 	for (int i = 0; i <= 10000; i++)
		if (bs(0, i - 1, k, m)) r[i] = 1;
}

void result()
{
	int i = 0, j;
	while (i < 10000)
	{
		while (!r[i] && i <= 10000) i++;
		if (i > 10000) break;
		j = i;
		while (j <= 10000 && r[j]) j++; j--;
		rr[res][0] = i;
		rr[res][1] = j; res++;
		i = j + 1;
	}
	printf("%d\n", res);
	for (i = 0; i < res; i++)
		printf("%d %d\n", rr[i][0], rr[i][1]);
}

int main()
{
#ifdef _DEBUG
	freopen("1064", "r", stdin);
//	freopen("out", "w", stdout);
#endif
	scanf("%d %d", &k, &m);
	solve();
	result();
	return 0;
}

