def main(): h, w = map(int, input().split()) A = [] for _ in range(h): A += list(input()) d = {A[0][0]: [0]} for _ in range(h + w - 1): s = min(d) q = [k for k in d[s]] d.clear() while q: k = q.pop() A[k] = A[k].upper() i, j = divmod(k, w) if i < h - 1: ni = (i + 1) * w + j a = A[ni] if a in d: d[a].append(ni) else: d[a] = [ni] if j < w - 1: nj = i * w + (j + 1) a = A[nj] if a in d: d[a].append(nj) else: d[a] = [nj] ans = [] i, j = h - 1, w - 1 for _ in range(h + w - 1): ans.append(A[i * w + j].lower()) if i > 0 and A[(i - 1) * w + j].isupper(): i -= 1 else: j -= 1 print(''.join(reversed(ans))) if __name__ == '__main__': main()