#include #include #define chmin(x,y) (x) = min((x),(y)) #define chmax(x,y) (x) = max((x),(y)) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define vec vector #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define pb push_back #define eb emplace_back using namespace std; using namespace atcoder; using ll = long long; using ld = long double; const ll mod = 998244353; using mint = modint998244353; const vector dx = {1,0,-1,0}, dy = {0,1,0,-1}; // using Graph = vector>>; using Graph = vector>; int main(){ // input + prep int N,M; cin >> N >> M; vector S(N), sort1(M); rep(i,N){ cin >> S[i]; rep(j,M) sort1[j] += S[i][j]; } // solve vector sort2(N); rep(j,M){ sort(all(sort1[j])); assert(sort1[j].size() == N); rep(i,N) sort2[i] += sort1[j][i]; } // output rep(i,N){ sort(all(sort2[i])); cout << sort2[i] << endl; } }