#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
const int mod = 1000000007;
const int MAXN = 100001;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  int c[n][m], r[n][m];
  int mxr[n], mxc[m];
  for (int i = 0; i < n; i++) {
    vector<pair<int, int> > v;
    for (int j = 0; j < m; j++) {
      v.push_back({a[i][j], j});
    }
    sort(v.begin(), v.end());
    r[i][v[0].second] = 1;
    for (int j = 1; j <= m - 1; j++) {
      r[i][v[j].second] =
          r[i][v[j - 1].second] + (int)(v[j].first > v[j - 1].first);
    }
  }
  for (int i = 0; i < n; i++) {
    mxr[i] = 0;
    for (int j = 0; j < m; j++) mxr[i] = max(mxr[i], r[i][j]);
  }
  for (int j = 0; j < m; j++) {
    vector<pair<int, int> > v;
    for (int i = 0; i < n; i++) {
      v.push_back({a[i][j], i});
    }
    sort(v.begin(), v.end());
    c[v[0].second][j] = 1;
    for (int i = 1; i <= n - 1; i++) {
      c[v[i].second][j] =
          c[v[i - 1].second][j] + (int)(v[i].first > v[i - 1].first);
    }
  }
  for (int j = 0; j < m; j++) {
    mxc[j] = 0;
    for (int i = 0; i < n; i++) mxc[j] = max(mxc[j], c[i][j]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int m1 = mxr[i], m2 = mxc[j];
      if (r[i][j] > c[i][j]) {
        m2 += r[i][j] - c[i][j];
      } else {
        m1 += c[i][j] - r[i][j];
      }
      cout << max(m1, m2) << ' ';
    }
    cout << '\n';
  }
}
