#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n;
  cin >> m >> n;
  int i = 0;
  vector<string> table(m * n, "");
  while (i < (m * n)) {
    string temp;
    cin >> temp;
    if (temp == "01") temp = "10";
    table[i] = temp;
    i++;
  }
  auto comp = [](string &a, string &b) {
    if (a[0] > b[0])
      return true;
    else if (a[0] < b[0])
      return false;
    else
      return a[1] > b[1];
  };
  sort(table.begin(), table.end(), comp);
  vector<vector<string>> re(m, vector<string>(n, ""));
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      string temp = table[i * n + j];
      if (i % 2) {
        reverse(temp.begin(), temp.end());
        re[i][n - 1 - j] = temp;
      } else
        re[i][j] = temp;
    }
    for (int j = 0; j < n; j++) {
      if (j != (n - 1))
        cout << re[i][j] << " ";
      else
        cout << re[i][j] << endl;
    }
  }
  return 0;
}
