#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
vector<long long> tate[1010], yoko[1010];
long long A[1010][1010];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, M;
  cin >> N >> M;
  for (long long i = (0); i < (N); i++) {
    for (long long j = (0); j < (M); j++) {
      cin >> A[i][j];
    }
  }
  for (long long i = (0); i < (N); i++) {
    for (long long j = (0); j < (M); j++) {
      yoko[i].push_back(A[i][j]);
      tate[j].push_back(A[i][j]);
    }
  }
  for (long long i = (0); i < (N); i++) {
    sort(yoko[i].begin(), yoko[i].end());
  }
  for (long long i = (0); i < (M); i++) {
    sort(tate[i].begin(), tate[i].end());
  }
  for (long long i = (0); i < (N); i++) {
    yoko[i].erase(unique(yoko[i].begin(), yoko[i].end()), yoko[i].end());
  }
  for (long long i = (0); i < (M); i++) {
    tate[i].erase(unique(tate[i].begin(), tate[i].end()), tate[i].end());
  }
  for (long long i = (0); i < (N); i++) {
    for (long long j = (0); j < (M); j++) {
      long long max_yoko = yoko[i].size();
      long long max_tate = tate[j].size();
      long long pos_yoko =
          upper_bound(yoko[i].begin(), yoko[i].end(), A[i][j]) -
          yoko[i].begin();
      long long pos_tate =
          upper_bound(tate[j].begin(), tate[j].end(), A[i][j]) -
          tate[j].begin();
      long long v1 = pos_tate;
      if (v1 - pos_yoko < 0) {
        v1 += abs(v1 - pos_yoko);
      }
      long long ans =
          max(v1 + (max_tate - pos_tate), v1 + (max_yoko - pos_yoko));
      cout << ans << " \n"[j == M - 1];
    }
  }
}
