#include <iostream>
using namespace std;
const int TEN = 10;
const int MAX_SIZE = 20;
bool isRecreatives(int num) {
return num / TEN / TEN == num / TEN % TEN && num / TEN % TEN == num % TEN;
}
int main() {
int n, m, matrix[MAX_SIZE][MAX_SIZE], distinctLines[MAX_SIZE] = {0};
int highestRecreatives = 1;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> matrix[i][j];
distinctLines[i] += (int)isRecreatives(matrix[i][j]);
}
if (highestRecreatives < distinctLines[i]) {
highestRecreatives = distinctLines[i];
}
}
for (int i = 0; i < n; ++i) {
if (distinctLines[i] == highestRecreatives) {
for (int j = 0; j < m; ++j) {
cout << matrix[i][j] << ' ';
}
cout << '\n';
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IFRFTiA9IDEwOwpjb25zdCBpbnQgTUFYX1NJWkUgPSAyMDsKCmJvb2wgaXNSZWNyZWF0aXZlcyhpbnQgbnVtKSB7CiAgICByZXR1cm4gbnVtIC8gVEVOIC8gVEVOID09IG51bSAvIFRFTiAlIFRFTiAmJiBudW0gLyBURU4gJSBURU4gPT0gbnVtICUgVEVOOwp9CgppbnQgbWFpbigpIHsKICAgIGludCBuLCBtLCBtYXRyaXhbTUFYX1NJWkVdW01BWF9TSVpFXSwgZGlzdGluY3RMaW5lc1tNQVhfU0laRV0gPSB7MH07CiAgICBpbnQgaGlnaGVzdFJlY3JlYXRpdmVzID0gMTsKICAgIGNpbiA+PiBuID4+IG07CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47ICsraSkgewogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgbTsgKytqKSB7CiAgICAgICAgICAgIGNpbiA+PiBtYXRyaXhbaV1bal07CiAgICAgICAgICAgIGRpc3RpbmN0TGluZXNbaV0gKz0gKGludClpc1JlY3JlYXRpdmVzKG1hdHJpeFtpXVtqXSk7CiAgICAgICAgfQogIC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