#include <bits/stdc++.h>
using namespace std;
const int N = 30;
int path[N];
bool st[N];
int n, m;
int cnt;
void dfs(int u)
{
if(u > m)
{
for(int i = 1; i <= m; i++) cout << path[i] << ' ';
cout << endl;
return;
}
for(int i = 1; i <= n; i++)
{
if(!st[i] && i > path[u-1])
{
st[i] = true;
path[u] = i;
dfs(u + 1);
st[i] = false;
}
}
}
int main()
{
cin >> n >> m;
dfs(1);
return 0;
}