#include <iostream>
#include <string>
using namespace std;
string arr;
bool input[9];
int n, m;
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])
{
input[i] = true;
arr.push_back(i + '0');
solution(position + 1);
input[i] = false;
arr.pop_back();
}
}
}
int main(void)
{
cin >> n >> m;
solution(0);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnN0cmluZyBhcnI7CmJvb2wgaW5wdXRbOV07CmludCBuLCBtOwoKdm9pZCBzb2x1dGlvbihpbnQgcG9zaXRpb24pCnsKCWlmIChwb3NpdGlvbiA9PSBtKQoJewoJCWZvciAoaW50IGkgPSAwOyBpIDwgbTsgaSsrKQoJCQljb3V0IDw8IGFycltpXSA8PCAiICI7CgkJY291dCA8PCAnXG4nOwoJCXJldHVybjsKCX0KCglmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpKyspCgl7CgkJaWYgKCFpbnB1dFtpXSkKCQl7CgkJCWlucHV0W2ldID0gdHJ1ZTsKCQkJYXJyLnB1c2hfYmFjayhpICsgJzAnKTsKCgkJCXNvbHV0aW9uKHBvc2l0aW9uICsgMSk7CgoJCQlpbnB1dFtpXSA9IGZhbHNlOwoJCQlhcnIucG9wX2JhY2soKTsKCQl9Cgl9Cn0KCmludCBtYWluKHZvaWQpCnsKCWNpbiA+PiBuID4+IG07Cglzb2x1dGlvbigwKTsKCXJldHVybiAwOwp9