'use strict'

function main(input) {
  input = input.split('\n').slice(0, -1);

  const H = Number(input[0].split(' ')[0]);
  const W = Number(input[0].split(' ')[1]);

  input.shift();

  const grid = input.map(n => n.split(''));
  const deleteH = [];
  const deleteW = [];

  for (let h = 0; h < H; h++) {
    if (grid[h].every((gr) => gr === grid[h][0])) deleteH.push(h);
  }

  for (let w = 0; w < W; w++) {
    let canDelete = true;

    for (let i = 0; i < H - 1; i++) {
      if (grid[i][w] !== grid[i + 1][w]) {
        canDelete = false;
      }
    }

    if (canDelete) {
      deleteW.push(w);
    }
  }

  for (let j = 0; j < deleteH.length; j++) {
    grid.splice(deleteH[j] - j, 1);
  }

  for (var l = 0; l < grid.length; l++) {
    for (let k = 0; k < deleteW.length; k++) {
      grid[l].splice(deleteW[k] - k, 1);
    }
  }

  const ans = grid.map(l => l.join('')).join('\n');

  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
