#include <bits/stdc++.h>
const long long md = 1e9 + 7;
const int Inf = 1e9;
using namespace std;
struct el {
  el() {}
  int gv, vv, ans;
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long N, M;
  cin >> N >> M;
  vector<vector<int> > Mt(N, vector<int>(M));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> Mt[i][j];
    }
  }
  vector<vector<int> > ver(N, vector<int>(M));
  vector<int> Max_ver(N, 0);
  for (int i = 0; i < N; i++) {
    vector<int> k(Mt[i]);
    sort(k.begin(), k.end());
    k.resize(unique(k.begin(), k.end()) - k.begin());
    map<int, int> Mp;
    for (auto j : k) Mp[j] = ++Max_ver[i];
    for (int j = 0; j < M; j++) ver[i][j] = Mp[Mt[i][j]];
  }
  vector<vector<int> > gor(N, vector<int>(M));
  vector<int> Max_gor(M, 0);
  for (int i = 0; i < M; i++) {
    vector<int> k(N);
    for (int j = 0; j < N; j++) {
      k[j] = Mt[j][i];
    }
    sort(k.begin(), k.end());
    k.resize(unique(k.begin(), k.end()) - k.begin());
    map<int, int> Mp;
    for (auto j : k) Mp[j] = ++Max_gor[i];
    for (int j = 0; j < N; j++) gor[j][i] = Mp[Mt[j][i]];
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      int pv = max(ver[i][j], gor[i][j]);
      int pg = max(Max_gor[j] - gor[i][j], Max_ver[i] - ver[i][j]);
      cout << pv + pg << ' ';
    }
    cout << '\n';
  }
  cerr << '\n'
       << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec"
       << '\n';
  return 0;
}
