#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long maxn = 1005;
const long long mod = 1e9 + 7;
long long n, m;
long long a[maxn][maxn];
long long vis[maxn];
long long rmax[maxn], cmax[maxn];
map<long long, long long> ma;
map<long long, long long> r[maxn], c[maxn];
long long dp[maxn][maxn];
int main() {
  scanf("%lld%lld", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%lld", &a[i][j]);
  int cnt;
  for (int i = 1; i <= n; i++) {
    ma.clear();
    cnt = 0;
    for (int j = 1; j <= m; j++) {
      if (ma[a[i][j]]) continue;
      vis[++cnt] = a[i][j];
      ma[a[i][j]] = 1;
    }
    sort(vis + 1, vis + cnt + 1);
    for (int j = 1; j <= cnt; j++) r[i][vis[j]] = j;
    rmax[i] = cnt;
  }
  for (int j = 1; j <= m; j++) {
    ma.clear();
    cnt = 0;
    for (int i = 1; i <= n; i++) {
      if (ma[a[i][j]]) continue;
      vis[++cnt] = a[i][j];
      ma[a[i][j]] = 1;
    }
    sort(vis + 1, vis + cnt + 1);
    for (int i = 1; i <= cnt; i++) c[j][vis[i]] = i;
    cmax[j] = cnt;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = max(r[i][a[i][j]] - 1, c[j][a[i][j]] - 1) +
                 max(rmax[i] - r[i][a[i][j]], cmax[j] - c[j][a[i][j]]) + 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) printf("%lld ", dp[i][j]);
    printf("\n");
  }
  return 0;
}
