#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int a[N][N], r[N][N], c[N][N], rr[N], cc[N];
pair<int, int> b[N];
int main() {
  int n, m, rec, ans;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      b[j].first = a[i][j];
      b[j].second = j;
    }
    sort(b + 1, b + m + 1);
    r[i][b[1].second] = 1;
    for (int j = 2; j <= m; j++) {
      if (b[j].first == b[j - 1].first)
        r[i][b[j].second] = r[i][b[j - 1].second];
      else
        r[i][b[j].second] = r[i][b[j - 1].second] + 1;
    }
    rr[i] = r[i][b[m].second];
  }
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++) {
      b[i].first = a[i][j];
      b[i].second = i;
    }
    sort(b + 1, b + n + 1);
    c[j][b[1].second] = 1;
    for (int i = 2; i <= n; i++) {
      if (b[i].first == b[i - 1].first)
        c[j][b[i].second] = c[j][b[i - 1].second];
      else
        c[j][b[i].second] = c[j][b[i - 1].second] + 1;
    }
    cc[j] = c[j][b[n].second];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      rec = max(r[i][j], c[j][i]);
      ans = rec + rr[i] - r[i][j];
      ans = max(ans, rec + cc[j] - c[j][i]);
      printf("%d ", ans);
    }
    printf("\n");
  }
  return 0;
}
