r, c = map(int, input().split())
c2 = c % 2
shift = False
for _ in range(r):
    s = input()
    n = len(s)
    offset = (c - n) // 2
    if n % 2 != c2:
        offset += int(shift)
        shift = not shift

    lhs = '.' * (offset)
    rhs = '.' * (c - n - offset)
    print(f"{lhs}{s}{rhs}")
