#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <map>
using namespace std;
typedef long long ll;

const int maxn = 1e5 + 10;
const ll INF = 1e16;


int power(int a, int b) {
    int res = 1;
    for(int i = 0; i < b; i++) {
        res *= a;
    }
    return res;
}
int n, k;
string to_binary(int x) {
    string res = "";
    
    while(x > 0) {
        int rem = x % 2;
        res += rem + '0';
        
        x /= 2;
    }
    while((int) res.size() < k) {
        res += "0";
    }
    reverse(res.begin(), res.end());
    return res;
}
int main()
{
    cin >> n;
    
    cin >> k;
    
    vector<string> v(k);
    for(int i =0 ; i < k; i++) {
        cin >> v[i];
    }
    
    int power_of_2 = power(2, k);
    
    for(int i = 0; i < power_of_2; i++) {
        string tmp = to_binary(i);
        vector<string> v_tmp;
        for(int j = 0; j < (int) tmp.size(); j++) {
            if(tmp[j] == '1') {
                v_tmp.push_back(v[j]);
            }
        }
        if((int) v_tmp.size() == n) {
            for(string s: v_tmp) {
                cout << s << " " ;
            }
            cout << endl;
        }
    }


    return 0;
}
