#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long double EPS = 1e-9;
long long binpow(long long b, long long p, long long mod) {
  long long ans = 1;
  b %= mod;
  for (; p; p >>= 1) {
    if (p & 1) ans = ans * b % mod;
    b = b * b % mod;
  }
  return ans;
}
void pre() {}
long long arr[1010][1010];
int row[1010][1010][2];
int col[1010][1010][2];
void solve() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < (n); ++i) {
    for (long long j = 0; j < (m); ++j) {
      cin >> arr[i][j];
    }
  }
  for (long long i = 0; i < (n); ++i) {
    set<long long> st;
    vector<long long> temp;
    for (long long j = 0; j < (m); ++j) {
      st.insert(arr[i][j]);
    }
    temp = vector<long long>((st).begin(), (st).end());
    for (long long j = 0; j < (m); ++j) {
      row[i][j][0] =
          lower_bound((temp).begin(), (temp).end(), arr[i][j]) - temp.begin();
      row[i][j][1] =
          upper_bound((temp).begin(), (temp).end(), arr[i][j]) - temp.begin();
      row[i][j][1] = (long long)(temp).size() - row[i][j][1];
    }
  }
  for (long long j = 0; j < (m); ++j) {
    set<long long> st;
    vector<long long> temp;
    for (long long i = 0; i < (n); ++i) {
      st.insert(arr[i][j]);
    }
    temp = vector<long long>((st).begin(), (st).end());
    for (long long i = 0; i < (n); ++i) {
      col[i][j][0] =
          lower_bound((temp).begin(), (temp).end(), arr[i][j]) - temp.begin();
      col[i][j][1] =
          upper_bound((temp).begin(), (temp).end(), arr[i][j]) - temp.begin();
      col[i][j][1] = (long long)(temp).size() - col[i][j][1];
    }
  }
  for (long long i = 0; i < (n); ++i) {
    for (long long j = 0; j < (m); ++j) {
      cout << max(row[i][j][0], col[i][j][0]) + 1 +
                  max(row[i][j][1], col[i][j][1])
           << " ";
    }
    cout << '\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  pre();
  long long t = 1;
  for (long long i = 1; i <= t; i++) {
    solve();
  }
}
