#include <bits/stdc++.h>
using namespace std;
int N, M;
int a = -1, b = -1, c = -1, d = -1;
char Tahta[51][51];
int main() {
  char x;
  cin >> M >> N;
  for (int i = 0; i < M; i++)
    for (int j = 0; j < N; j++) {
      cin >> x;
      Tahta[i][j] = x;
      if (x == '.') continue;
      if (a == -1) {
        a = i;
        c = i;
      }
      if (b == -1) {
        b = j;
        d = j;
      }
      if (c < i) c = i;
      if (d < j) d = j;
      if (b > j) b = j;
    }
  for (int i = a; i <= c; i++, cout << endl)
    for (int j = b; j <= d; j++) cout << Tahta[i][j];
  return 0;
}
