import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, M = map(int, readline().split()) if N > 3: filter = np.random.randint(0, 10**18, (N - 3, N - 3), dtype=np.uint64) def compute_hash(A): if A.shape[0] <= 3: return np.zeros(A.shape[2], np.uint64) A = A == b'#' # 2x2ごとの集計を並べる A = A[:-1] ^ A[1:] A = A[:, :-1] ^ A[:, 1:] # ななめに2x2 A = A[1:, :-1] ^ A[:-1, 1:] A = A[:-1, :-1] ^ A[1:, 1:] return np.sum(A * filter[:, :, None], axis=(0, 1)) A = np.empty((N * N + N + 1) * M, 'S1') A[:-1] = np.frombuffer(read(), 'S1') A = A.reshape(M, -1)[:, :-1].reshape(M, N, -1)[:, :, :-1] H = compute_hash(A.T) ok = (np.equal.outer(H, H) * 1).astype(str) answers = (''.join(ok[i, i + 1:]) for i in range(M - 1)) print('\n'.join(answers))