#include
int month[13] =
{
0, 31, 0, 31, 30,
31, 30, 31, 31,
30, 31, 30, 31
};
int leapyear(int y)
{
return y % 4 == 0 && y % 100 != 0 || y % 400 == 0;
}
int main(void)
{
int year, n; scanf("%d %d", &year, &n);
month[2] = 28 + leapyear(year);
int i, j, m = n;
for(i = 0; i < n; i++)
printf("%3c", ' ');
for(i = 1; i <= 12; i++)
{
for(j = 1; j <= month[i]; j++)
{
printf("%3d", j);
m++;
if(m % 7 == 0)
{
puts("");
m = 0;
}
}
printf("\n");
for(j = 0; j < m; j++)
printf("%3c", ' ');
}
return 0;
}