#include <bits/stdc++.h>
using namespace std;
struct pp {
  int ord;
  int num;
};
bool cmp1(pp a, pp b) { return (a.num < b.num); }
int a[1005][1005];
int x[1005][1005];
int y[1005][1005];
int ans[1005][1005];
int xmax[1005];
int ymax[1005];
pp d[1005];
int main() {
  int n, m;
  int lastj, lastord;
  int xm, ym;
  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++) {
      d[j].ord = j;
      d[j].num = a[i][j];
    }
    sort(d, d + m, cmp1);
    lastj = 0;
    lastord = 1;
    for (int j = 0; j < m; j++) {
      if (d[j].num != d[lastj].num) {
        lastj = j;
        lastord++;
      }
      x[i][d[j].ord] = lastord;
    }
    xmax[i] = lastord;
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      d[j].ord = j;
      d[j].num = a[j][i];
    }
    sort(d, d + n, cmp1);
    lastj = 0;
    lastord = 1;
    for (int j = 0; j < n; j++) {
      if (d[j].num != d[lastj].num) {
        lastj = j;
        lastord++;
      }
      y[d[j].ord][i] = lastord;
    }
    ymax[i] = lastord;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      xm = xmax[i];
      ym = ymax[j];
      if (x[i][j] > y[i][j])
        ym += (x[i][j] - y[i][j]);
      else
        xm += (y[i][j] - x[i][j]);
      if (xm > ym)
        ans[i][j] = xm;
      else
        ans[i][j] = ym;
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (j == m - 1)
        printf("%d\n", ans[i][j]);
      else
        printf("%d ", ans[i][j]);
}
