h,w = map(int,input().split()) S = [input() for i in range(h)] ans = [] vis = [[0]*w for i in range(h)] ans.append(S[0][0]) l = [[0,0]] for i in range(h+w-1): cands = [[] for j in range(26)] for x,y in l: nx,ny = x+1,y if 0 <= nx < h and 0 <= ny < w and vis[nx][ny] == 0: cands[ord(S[nx][ny])-ord("a")].append([nx,ny]) vis[nx][ny] = 1 nx,ny = x,y+1 if 0 <= nx < h and 0 <= ny < w and vis[nx][ny] == 0: cands[ord(S[nx][ny])-ord("a")].append([nx,ny]) vis[nx][ny] = 1 for j in range(26): if cands[j] != []: l = cands[j] ans.append(chr(j+ord("a"))) break print(*ans,sep="")