#include<iostream>
using namespace std;
int n, m, a[25], cnt = 0;
bool vis[25];
void search(int t)
{
if(t > m)
{
cnt++;
for(int i = 1; i <= m; i++)
cout << a[i] << " ";
cout << endl;
return;
}
for(int i = 1; i <= n; i++)
{
if(vis[i] == true) continue;
vis[i] = true;
a[t] = i;
search(t + 1);
vis[i] = false;
}
}
int main()
{
cin >> n >> m;
search(1);
cout << cnt << endl;
return 0;
}