#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  vector<vector<long> > A, Row, Col;
  long M, N, L1, L2, R1, R2;
  cin >> N >> M;
  A.resize(N, vector<long>(M));
  Row.resize(N);
  Col.resize(M);
  for (long i = 0; i < N; ++i)
    for (long j = 0; j < M; ++j) {
      cin >> A[i][j];
      Row[i].push_back(A[i][j]);
      Col[j].push_back(A[i][j]);
    }
  for (long i = 0; i < N; ++i) {
    sort(Row[i].begin(), Row[i].end());
    Row[i].resize(
        distance(Row[i].begin(), unique(Row[i].begin(), Row[i].end())));
  }
  for (long i = 0; i < M; ++i) {
    sort(Col[i].begin(), Col[i].end());
    Col[i].resize(
        distance(Col[i].begin(), unique(Col[i].begin(), Col[i].end())));
  }
  for (long i = 0; i < N; ++i) {
    for (long j = 0; j < M; ++j) {
      L1 = lower_bound(Row[i].begin(), Row[i].end(), A[i][j]) - Row[i].begin();
      L2 = lower_bound(Col[j].begin(), Col[j].end(), A[i][j]) - Col[j].begin();
      R1 =
          Row[i].end() - upper_bound(Row[i].begin(), Row[i].end(), A[i][j]) + 1;
      R2 =
          Col[j].end() - upper_bound(Col[j].begin(), Col[j].end(), A[i][j]) + 1;
      cout << max(L1, L2) + max(R1, R2) << ' ';
    }
    cout << endl;
  }
  return 0;
}
