// Arup Guha
// 10/17/2014
// Solution to 1994 UCF HS Contest Problem: Snail

import java.util.*;

public class snail {

	public static void main(String[] args) {

		// Process all cases
		Scanner stdin = new Scanner(System.in);
		while (stdin.hasNext()) {

			// Read in the case.
			int r = stdin.nextInt();
			int c = stdin.nextInt();
			char[][] grid = new char[r][c];
			for (int i=0; i<r; i++)
				for (int j=0; j<c; j++)
					grid[i][j] = stdin.next().charAt(0);

			// Print it!
			print(grid,0,0,r,c);
			System.out.println("\n");
		}
	}

	// Prints the portion of the grid starting at (sr, sc) with window size depthxheight
	public static void print(char[][] grid, int sr, int sc, int height, int width) {

		// Base cases.
		if (height == 0 || width == 0) return;
		if (height == 1 || width == 1) {
			for (int i=sr; i<sr+height; i++)
				for (int j=sc; j<sc+width; j++)
					System.out.print(grid[i][j]);
			return;
		}

		// Print outer ring.
		for (int i=sc; i<sc+width-1; i++)  System.out.print(grid[sr][i]);
		for (int i=sr; i<sr+height-1; i++) System.out.print(grid[i][sc+width-1]);
		for (int i=sc+width-1; i>sc; i--)  System.out.print(grid[sr+height-1][i]);
		for (int i=sr+height-1; i>sr; i--) System.out.print(grid[i][sc]);

		// Recurse for inner grid.
		print(grid, sr+1, sc+1, height-2, width-2);
	}
}