#include <bits/stdc++.h>
using namespace std;
const int N = 1050;
const int inf = 0x3f3f3f3f;
const long long llinf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end() {}
int n, m;
int a[N][N];
int b[N][N], c[N][N];
int cnt[2][N][N];
vector<int> vec;
int sum[2][N];
inline void solve() {
  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) {
    vec.resize(0);
    for (int j = 1; j <= m; ++j) vec.push_back(a[i][j]);
    (sort((vec).begin(), (vec).end()));
    ((vec).resize(unique((vec).begin(), (vec).end()) - (vec).begin()));
    int mm = vec.size();
    for (int j = 0; j < (int)vec.size(); ++j) cnt[0][i][j + 1] = 1;
    for (int j = 1; j <= mm; ++j) cnt[0][i][j + 1] += cnt[0][i][j];
    sum[0][i] = mm;
    for (int j = 1; j <= m; ++j)
      b[i][j] =
          lower_bound((vec).begin(), (vec).end(), a[i][j]) - vec.begin() + 1;
  }
  for (int j = 1; j <= m; ++j) {
    vec.resize(0);
    for (int i = 1; i <= n; ++i) vec.push_back(a[i][j]);
    (sort((vec).begin(), (vec).end()));
    ((vec).resize(unique((vec).begin(), (vec).end()) - (vec).begin()));
    int mm = vec.size();
    for (int i = 0; i < (int)vec.size(); ++i) cnt[1][j][i + 1] = 1;
    for (int i = 1; i <= mm; ++i) cnt[1][j][i + 1] += cnt[1][j][i];
    sum[1][j] = mm;
    for (int i = 1; i <= n; ++i)
      c[i][j] =
          lower_bound((vec).begin(), (vec).end(), a[i][j]) - vec.begin() + 1;
  }
  for (int i = 1; i <= n; ++i, puts(""))
    for (int j = 1; j <= m; ++j) {
      int ans1 = max(cnt[0][i][b[i][j] - 1], cnt[1][j][c[i][j] - 1]);
      int ans2 =
          max(sum[0][i] - cnt[0][i][b[i][j]], sum[1][j] - cnt[1][j][c[i][j]]);
      printf("%d ", ans1 + ans2 + 1);
    }
}
int main() {
  TIME__START = clock();
  int Test = 1;
  while (Test--) solve();
  TIME__END = clock();
  program_end();
  return 0;
}
