H, W = list(map(int, input().split())) S = [input() for _ in range(H)] T = '' def pick_right(h, w): if w == W - 1: return None return S[h][w + 1] def pick_below(h, w): if h == H - 1: return None return S[h + 1][w] def move(h, w): right = pick_right(h, w) below = pick_below(h, w) if right is None and below is None: return None if right is None: return (h + 1, w) if below is None: return (h, w + 1) if right > below: return (h + 1, w) if right < below: return (h , w + 1) flag = True h, w = 0, 0 while(flag): T += S[h][w] p = move(h, w) if p is None: flag = False break h, w = p[0], p[1] print(T)