#include<bits/stdc++.h>
using namespace std;
int visited[11],n,k;
void bfs(int rst,string a){
if(rst == 0){cout << a << endl;return;}
for(int i = 1;i <= n;i++){
if(visited[i]) continue;
visited[i] = 1;
bfs(rst - 1,a + to_string(i) + " ");
visited[i] = 0;
}
}
int main(){
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for(int i = 1;i <= n;i++){
visited[i] = 1;
bfs(k - 1,to_string(i) + " ");
visited[i] = 0;
}
return 0;
}