import sys input = sys.stdin.readline H, W = map(int, input().split()) S = [input()[:-1] for _ in range(H)] now = {(0, 0)} ans = [S[0][0]] for _ in range(H+W-2): m = 'z' nex = set() for x, y in now: if x+1S[x+1][y]: m = S[x+1][y] nex = {(x+1, y)} if y+1S[x][y+1]: m = S[x][y+1] nex = {(x, y+1)} ans.append(m) now = nex print(''.join(ans))