h,w = map(int, input().split()) Alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" alpha = "abcdefghijklmnopqrstuvwxyz" Dict_alpha = {} dict_alpha = {} for i in range(26): Dict_alpha[Alpha[i]] = i dict_alpha[alpha[i]] = i Dec = lambda x:Dict_alpha[x] dec = lambda x:dict_alpha[x] s = [list(map(dec, list(input()))) + [26] for i in range(h)] + [[26] * w] #print(s) st = [(0,0)] ans = [alpha[s[0][0]]] for i in range(h+w-2): mn = 100 nst = [] for jx, jy in st: t = s[jx+1][jy] if t == mn: nst.append((jx+1, jy)) elif t < mn: mn = t nst = [(jx+1, jy)] t = s[jx][jy+1] if t == mn: nst.append((jx, jy+1)) elif t < mn: mn = t nst = [(jx, jy+1)] st = nst #print(mn) ans.append(alpha[mn]) print("".join(ans))