import java.io.*; import java.util.*; public class Main { static char[][] field; static int h; static int w; static String[][] dp; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); h = sc.nextInt(); w = sc.nextInt(); field = new char[h][]; for (int i = 0; i < h; i++) { field[i] = sc.next().toCharArray(); } dp = new String[h][w]; dp[h - 1][w - 1] = String.valueOf(field[h - 1][w - 1]); System.out.println(dfw(0, 0)); } static String dfw(int r, int c) { if (dp[r][c] == null) { if (r == h - 1) { dp[r][c] = field[r][c] + dfw(r, c + 1); } else if (c == w - 1) { dp[r][c] = field[r][c] + dfw(r + 1, c); } else { String s1 = dfw(r, c + 1); String s2 = dfw(r + 1, c); if (s1.compareTo(s2) < 0) { dp[r][c] = field[r][c] + s1; } else { dp[r][c] = field[r][c] + s2; } } } return dp[r][c]; } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }