#include <stdio.h>
#define MAX 5
int main(void)
{
    int a[MAX][MAX], b[MAX][MAX], rows, columns, i, j;
    if (scanf("%d%d", &rows, &columns) != 2 || rows < 1 || rows > MAX || columns < 1 || columns > MAX) {
        puts("Enter rows and columns from 1 to 5.");
        return 1;
    }
    for (i = 0; i < rows; i++) {
        for (j = 0; j < columns; j++) {
            if (scanf("%d", &a[i][j]) != 1 || a[i][j] < -20 || a[i][j] > 20) {
                puts("Enter matrix values from -20 to 20."); return 1;
            }
        }
    }
    for (i = 0; i < rows; i++) {
        for (j = 0; j < columns; j++) {
            if (scanf("%d", &b[i][j]) != 1 || b[i][j] < -20 || b[i][j] > 20) {
                puts("Enter matrix values from -20 to 20."); return 1;
            }
        }
    }
    puts("Sum:");
    for (i = 0; i < rows; i++) {
        for (j = 0; j < columns; j++) printf("%s%d", j ? " " : "", a[i][j] + b[i][j]);
        putchar('\n');
    }
    puts("Difference (A - B):");
    for (i = 0; i < rows; i++) {
        for (j = 0; j < columns; j++) printf("%s%d", j ? " " : "", a[i][j] - b[i][j]);
        putchar('\n');
    }
    return 0;
}
