class Node:
    def _init_(self, key):
        self.key = key
        self.left = None
        self.right = None

def insert(root, key):
    if not root:
        return Node(key)
    if key < root.key:
        root.left = insert(root.left, key)
    else:
        root.right = insert(root.right, key)
    return root

def inorder(root, result):
    if root:
        inorder(root.left, result)
        result.append(root.key)
        inorder(root.right, result)

def bst_inorder():
    try:
        n = int(input().strip())
        if n < 0 or n > 10:
            print("Invalid input")
            return
        if n == 0:
            print("Tree is Empty")
            return
        keys = []
        for _ in range(n):
            key = int(input().strip())
            if key < -100 or key > 100:
                print("Invalid input")
                return
            keys.append(key)

        root = None
        for key in keys:
            root = insert(root, key)

        result = []
        inorder(root, result)
        for val in result:
            print(val)
    except:
        print("Invalid input")

# Example usage:
# bst_inorder()




# Read the dimensions of the matrices
try:
    m, n = map(int, input().split())
except ValueError:
    print("Invalid input")
    exit()

# Check for valid dimensions
if not (1 <= m <= 100 and 1 <= n <= 100):
    print("Invalid input")
    exit()

# Read the first matrix
matrix1 = []
for _ in range(m):
    try:
        row = list(map(int, input().split()))
        if len(row) != n:
            raise ValueError
        matrix1.append(row)
    except ValueError:
        print("Invalid input")
        exit()

# Read the second matrix
matrix2 = []
for _ in range(m):
    try:
        row = list(map(int, input().split()))
        if len(row) != n:
            raise ValueError
        matrix2.append(row)
    except ValueError:
        print("Invalid input")
        exit()

# Perform element-wise addition and print the resulting matrix
for i in range(m):
    result_row = []
    for j in range(n):
        result_row.append(matrix1[i][j] + matrix2[i][j])
    print(*result_row)