#include #define rep(i,s,n) for (int i = s; i < (n); ++i) using namespace std; using ll = long long; using P = pair; using field = vector>; int main() { int h,w; cin >> h >> w; vector a(h*w); rep(i,0,h*w) cin >> a[i]; sort(a.begin(), a.end()); rep(i,0,h) { rep(j,0,w) { cout << a[i*w+j] << " "; } cout << "\n"; } return 0; }