/************************************************
Algorithmen und Problemloesungen mit C++,
http://www.algorithmen-und-problemloesungen.de
Copyright @2006-2007, Doina Logofatu
************************************************/

#include <fstream>
#include <iostream>
#include <vector>

using namespace std;

void writeSolution(vector<short> &x, ofstream &fout){
  for(size_t i=0; i<x.size(); i++)  
    fout << x[i]+1 << " ";
  fout << endl;
}

int main(){
  short n, m, k, i, noSol=0;
  vector<short> x;
  bool flag;
  cout << " n = "; cin >> n;
  cout << " m = "; cin >> m;
  ofstream fout("nmATowers.out");
  x.push_back(-1);
  while(!x.empty()){
    k = (short)x.size()-1;
    flag = false;
    while(!flag && x[k]<n-1){
      x[k]++; flag = true;
      for(i=0; i<k; i++)
        if(x[i]==x[k] || (k>0 && x[k-1]>x[k])) flag=false;
    }
  if(flag){
    if(k==m-1){
      writeSolution(x, fout);
      noSol++;
    }else
       x.push_back(-1);
    }else x.pop_back();
  }
  fout << n << " " << m << " " << noSol;
  return 0;
}

