#include <bits/stdc++.h>
using namespace std;
long long a[300000], ind[300000];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  long long a[n + 1][m + 1], ans[n + 1][m + 1];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  vector<vector<long long> > row(n + 1), col(m + 1);
  set<long long>::iterator it;
  for (int i = 1; i <= n; i++) {
    set<long long> st;
    for (int j = 1; j <= m; j++) st.insert(a[i][j]);
    for (it = st.begin(); it != st.end(); it++) row[i].push_back(*(it));
  }
  for (int j = 1; j <= m; j++) {
    set<long long> st;
    for (int i = 1; i <= n; i++) st.insert(a[i][j]);
    for (it = st.begin(); it != st.end(); it++) col[j].push_back(*(it));
  }
  vector<long long>::iterator itr, itc;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      long long rl, cl, rm, cm;
      itr = lower_bound(row[i].begin(), row[i].end(), a[i][j]);
      rl = itr - row[i].begin();
      itc = lower_bound(col[j].begin(), col[j].end(), a[i][j]);
      cl = itc - col[j].begin();
      itr = upper_bound(row[i].begin(), row[i].end(), a[i][j]);
      if (itr == row[i].end())
        rm = 0;
      else
        rm = row[i].size() - (itr - row[i].begin());
      itc = upper_bound(col[j].begin(), col[j].end(), a[i][j]);
      if (itc == col[j].end())
        cm = 0;
      else
        cm = col[j].size() - (itc - col[j].begin());
      ans[i][j] = max(rl, cl) + 1 + max(cm, rm);
      cout << ans[i][j] << " ";
    }
    cout << "\n";
  }
}
