#include<stdio.h>
#include <iostream.h>
#include <vector>
#include <queue>
using namespace std;

struct Element {
    int value;
    int streamIndex;
    int elementIndex;

    bool operator>(const Element& other) const {
        return value > other.value;
    }
};

int main() {
    int K, D;
    cin >> K >> D;

    vector<vector<int>> streams(K);
    for (int i = 0; i < K; ++i) {
        streams[i].resize(D);
        for (int j = 0; j < D; ++j) {
            cin >> streams[i][j];
        }
    }

    priority_queue<Element, vector<Element>, greater<Element>> pq;

    // Initialize with first element of each stream
    for (int i = 0; i < K; ++i) {
        pq.push({streams[i][0], i, 0});
    }

    while (!pq.empty()) {
        Element curr = pq.top();
        pq.pop();
        cout << curr.value << " ";

        int nextIndex = curr.elementIndex + 1;
        if (nextIndex < D) {
            pq.push({streams[curr.streamIndex][nextIndex], curr.streamIndex, nextIndex});
        }
    }

    return 0;
}