#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
void solve() {
  int n, m;
  cin >> n >> m;
  int arr[n][m];
  int R[n][m];
  int C[m][n];
  int MR[n];
  int MC[m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> arr[i][j];
  }
  for (int i = 0; i < n; i++) {
    set<int> s;
    for (int j = 0; j < m; j++) {
      s.insert(arr[i][j]);
    }
    map<int, int> M;
    int cnt = 1;
    for (auto j : s) {
      M[j] = cnt;
      cnt++;
    }
    cnt--;
    MR[i] = cnt;
    for (int j = 0; j < m; j++) {
      R[i][j] = M[arr[i][j]];
    }
  }
  for (int i = 0; i < m; i++) {
    set<int> s;
    for (int j = 0; j < n; j++) {
      s.insert(arr[j][i]);
    }
    map<int, int> M;
    int cnt = 1;
    for (auto j : s) {
      M[j] = cnt;
      cnt++;
    }
    cnt--;
    MC[i] = cnt;
    for (int j = 0; j < n; j++) {
      C[i][j] = M[arr[j][i]];
    }
  }
  int ans[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (R[i][j] == C[j][i]) {
        ans[i][j] = max(MR[i], MC[j]);
        continue;
      }
      if (R[i][j] > C[j][i]) {
        int X = R[i][j] - C[j][i];
        ans[i][j] = max(MR[i], MC[j] + X);
        continue;
      }
      if (R[i][j] < C[j][i]) {
        int X = C[j][i] - R[i][j];
        ans[i][j] = max(MR[i] + X, MC[j]);
        continue;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << ans[i][j] << " ";
    cout << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tests = 1;
  while (tests--) {
    solve();
  }
}
