h,w = map(int,input().split()) s = [input() for i in range(h)] # BFSっぽいのをする. (ただし少し特殊) mada = [(0,0)] t = [0] * h*w t[0] = 1 while mada: k = 26 for x, y in mada: if x < h-1: k = min(k, ord(s[x+1][y]) - ord("a")) if y < w-1: k = min(k, ord(s[x][y+1]) - ord("a")) fr = [] for x, y in mada: if x < h-1: if ord(s[x+1][y]) - ord("a") == k: if t[(x+1)*w + y] == 0: fr.append((x+1, y)) t[(x+1)*w + y] = 1 if y < w-1: if ord(s[x][y+1]) - ord("a") == k: if t[x*w + y+1] == 0: fr.append((x, y+1)) t[x*w + y+1] = 1 mada = fr ans = [] x = h-1; y = w-1 while x > 0 or y > 0: if x > 0 and t[(x-1)*w + y] == 1: ans.append(s[x][y]) x -= 1 elif y > 0 and t[x*w + y-1] == 1: ans.append(s[x][y]) y -= 1 ans.append(s[0][0]) print("".join(ans[::-1]))