//  A - Grid Compression
#define DaAbyad ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, MOD = 1e9 + 7;
const long long oo = 1e18 + 5;
const long double pi = acos(-1);
const long double eps = 1e-9;
void open_file(string filename) {
  freopen((filename + ".in").c_str(), "r", stdin);
  freopen((filename + ".out").c_str(), "w", stdout);
}

void Magic() {
  int n, m;
  cin >> n >> m;
  char a[n][m];
  bool goodRow[n], goodCol[m];
  memset(goodRow, 0, sizeof goodRow);
  memset(goodCol, 0, sizeof goodCol);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
      if (a[i][j] == 'B') {
        goodRow[i] = true;
        goodCol[j] = true;
      }
    }
  }

  for (int i = 0; i < n; ++i) {
    if (goodRow[i]) {
      for (int j = 0; j < m; ++j) {
        if (goodCol[j]) {
          cout << a[i][j];
        }
      }
      cout << "\n";
    }
  }
}

int main() {
  DaAbyad
  int tests = 1;
  // cin >> tests;
  while (tests--) {
    Magic();
  }
  return 0;
}