import java.util.Scanner;
public class Main {
static StringBuilder sb = new StringBuilder();
static int N, M;
static int[] select;
static void rec_func(int k) {
if (k == M + 1) {
for (int i = 1; i <= M; i++) {
sb.append(select[i]).append(' ');
}
sb.append('\n');
} else {
for (int j = 1; j <= N; j++) {
boolean isUsed = false;
for (int i = 1; i < k; i++) {
if (j == select[i]) {
isUsed = true;
break;
}
}
if (!isUsed) {
select[k] = j;
rec_func(k + 1);
select[k] = 0;
}
}
}
}
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
N = kb.nextInt();
M = kb.nextInt();
select = new int[M + 1];
rec_func(1);
System.out.print(sb);
}
}