// Arup Guha
// 11/8/2025
// Solution to 2025 SER D2 Problem A: Snakey String
// Written during contest, commented later.

import java.util.*;

public class snakeystring {

	public static void main(String[] args) {
	
		// Read in the grid.
		Scanner stdin = new Scanner(System.in);
		int r = stdin.nextInt();
		int c = stdin.nextInt();
		char[][] grid = new char[r][];
		for (int i=0; i<r; i++)
			grid[i] = stdin.next().toCharArray();
			
		// Just scan each column one by one until you find a letter.
		char[] res = new char[c];
		for (int i=0; i<c; i++) {
			for (int j=0; j<r; j++) {
				if (grid[j][i] >= 'A' && grid[j][i] <= 'Z') {
					res[i] = grid[j][i];
					break;
				}				
			}
		}
		
		// This is our answer.
		System.out.println(new String(res));
	}
}