#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
vector<int> a;
int n, m;
int mp[maxn][maxn];
int dis[maxn];
int hang[maxn][maxn], lie[maxn][maxn], ans[maxn][maxn];
int h[maxn], l[maxn];
int getval(int x, int i) {
  return lower_bound(a.begin(), a.begin() + i, x) - a.begin() + 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &mp[i][j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    a.clear();
    for (int j = 1; j <= m; j++) {
      a.push_back(mp[i][j]);
    }
    sort(a.begin(), a.end());
    h[i] = unique(a.begin(), a.end()) - a.begin();
    for (int j = 1; j <= m; j++) {
      hang[i][j] = getval(mp[i][j], h[i]);
    }
  }
  for (int i = 1; i <= m; i++) {
    a.clear();
    for (int j = 1; j <= n; j++) {
      a.push_back(mp[j][i]);
    }
    sort(a.begin(), a.end());
    l[i] = unique(a.begin(), a.end()) - a.begin();
    for (int j = 1; j <= n; j++) {
      lie[j][i] = getval(mp[j][i], l[i]);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int x = hang[i][j], y = lie[i][j];
      ans[i][j] = max(h[i], l[j]);
      if (x >= y) {
        ans[i][j] = max(h[i], x + l[j] - y);
      } else {
        ans[i][j] = max(l[j], y + h[i] - x);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      printf("%d ", ans[i][j]);
    }
    printf("\n");
  }
  return 0;
}
