#include <iostream>
#include <string>
using namespace std;
int n, m;
string arr;
bool input[9];
void solution(int position)
{
if (position == m)
{
for (int i = 0; i < m; i++)
cout << arr[i] << " ";
cout << "\n";
return;
}
for (int i = 1; i <= n; i++)
{
if (!input[i])
{
for (int j = 1; j <= i; j++)
input[j] = true;
arr.push_back(i + '0');
solution(position + 1);
for (int j = 1; j <= i; j++)
input[j] = false;
arr.pop_back();
}
}
}
int main(void)
{
cin >> n >> m;
solution(0);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG4sIG07CnN0cmluZyBhcnI7CmJvb2wgaW5wdXRbOV07Cgp2b2lkIHNvbHV0aW9uKGludCBwb3NpdGlvbikKewoJaWYgKHBvc2l0aW9uID09IG0pCgl7CgkJZm9yIChpbnQgaSA9IDA7IGkgPCBtOyBpKyspCgkJCWNvdXQgPDwgYXJyW2ldIDw8ICIgIjsKCQljb3V0IDw8ICJcbiI7CgkJcmV0dXJuOwoJfQoKCWZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkrKykKCXsKCQlpZiAoIWlucHV0W2ldKQoJCXsKCQkJZm9yIChpbnQgaiA9IDE7IGogPD0gaTsgaisrKQoJCQkJaW5wdXRbal0gPSB0cnVlOwoKCQkJYXJyLnB1c2hfYmFjayhpICsgJzAnKTsKCgkJCXNvbHV0aW9uKHBvc2l0aW9uICsgMSk7CgoJCQlmb3IgKGludCBqID0gMTsgaiA8PSBpOyBqKyspCgkJCQlpbnB1dFtqXSA9IGZhbHNlOwoKCQkJYXJyLnBvcF9iYWNrKCk7CgkJfQoJfQp9CmludCBtYWluKHZvaWQpCnsKCWNpbiA+PiBuID4+IG07Cglzb2x1dGlvbigwKTsKCXJldHVybiAwOwp9