#include <bits/stdc++.h>
using namespace std;
const char el = '\n';
typedef long long ll;
typedef unsigned long long ull;
struct number {
array<ull, 5> a;
void add(int p, int v) { a[p >> 4] += v << (p & 15); }
void sub(int p, int v) { a[p >> 4] -= v << (p & 15); }
string tostr
};
bool operator<(const number &a, const number &b) { return a.a < b.a; }
void gen(vector<bool> &inc, int lim, vector<string> &res, string &s, int pos,
int siz) {
if (res.size() == siz) return;
if (lim > (int)s.size() - pos) return;
// if (lim < 0) cout << "fuck" << el;
// cout << lim << el;
// if (lim == 0 && pos != s.size()) cout << lim << ' ' << pos << ' ' << s <<
// el;
if (pos == s.size()) {
res.push_back(s);
return;
}
for (s[pos] = '0'; s[pos] <= '9'; s[pos]++)
gen(inc, lim - (int)inc[s[pos] - '0'], res, s, pos + 1, siz);
}
vector<string> gen(vector<bool> &inc, int lim, int len, int k) {
vector<string> res;
for (string s = " "; res.size() < k && s.size() <= len; s.push_back(' ')) {
for (s[0] = '1'; s[0] <= '9'; s[0]++)
gen(inc, lim - (int)(inc[s[0] - '0']), res, s, 1, k);
}
return res;
}
bool comp(string a, string b) {
if (a.size() != b.size()) return a.size() < b.size();
return a < b;
}
vector<string> comb(vector<string> a, vector<string> b, int k) {
vector<string> c;
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
while (c.size() < k) {
if (!a.size())
c.push_back(b.back()), b.pop_back();
else if (!b.size())
c.push_back(a.back()), a.pop_back();
else if (a.back() == b.back()) {
c.push_back(a.back());
a.pop_back(), b.pop_back();
continue;
} else if (comp(a.back(), b.back()))
c.push_back(a.back()), a.pop_back();
else
c.push_back(b.back()), b.pop_back();
}
return c;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(15);
int n, k;
cin >> n >> k;
vector<int> a(n);
for (auto &v : a) {
for (int i = 0; i < 6; i++) {
int x;
cin >> x;
v |= 1 << x;
}
}
vector<string> res(1, string(200, 'x'));
// cout << res[0] << el;
// return 0;
vector<int> mask;
for (int i = 1; i < (1 << 10); i++) mask.push_back(i);
vector<int> cnt(1 << 10);
for (int i = 1; i < (1 << 10); i++)
for (auto v : a)
if (v & i) cnt[i]++;
sort(mask.begin(), mask.end(), [&](int a, int b) { return cnt[a] < cnt[b]; });
for (auto msk : mask) {
vector<bool> inc(10);
for (int i = 0; i < 10; i++) inc[i] = msk >> i & 1;
// continue;
// if (mask == (1 << 5)) {
// cout << mask << ' ' << cnt << el;
// for (auto s : gen(inc, cnt + 1, k)) cout << s << ' ';
// cout << el;
// }
// cout << mask << ' ' << cnt << el;
res = comb(res, gen(inc, cnt[msk] + 1, min((int)res.back().size(), 67), k), k);
}
for (auto s : res) cout << s << ' ';
cout << el;
return 0;
}