#include <bits/stdc++.h>

using namespace std;
const int N = 1010;
int a[N][N], a2[N];
struct {
    int lr, gr, lc, gc;
} b[N][N];

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            scanf("%d", &a[i][j]);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) a2[j] = a[i][j];
        sort(a2, a2 + m);
        auto ed = unique(a2, a2 + m);
        for (int j = 0; j < m; j++) {
            b[i][j].lr = lower_bound(a2, ed, a[i][j]) - a2;
            b[i][j].gr = ed - upper_bound(a2, ed, a[i][j]);
        }
    }
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) a2[j] = a[j][i];
        sort(a2, a2 + n);
        auto ed = unique(a2, a2 + n);
        for (int j = 0; j < n; j++) {
            b[j][i].lc = lower_bound(a2, ed, a[j][i]) - a2;
            b[j][i].gc = ed - upper_bound(a2, ed, a[j][i]);
        }
    }
    for (int i = 0; i < n; i++, putchar('\n'))
        for (int j = 0; j < m; j++, putchar(' '))
            printf("%d", max(b[i][j].lr, b[i][j].lc) + max(b[i][j].gr, b[i][j].gc) + 1);
    return 0;
}