#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  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 ur[n], uc[m];
  int rr[n][m], rc[n][m];
  set<pair<int, int>> v;
  int ans[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      v.insert({a[i][j], j});
    }
    pair<int, int> p = *v.begin();
    v.erase(v.begin());
    int prev = p.first;
    int curr = 1;
    rr[i][p.second] = curr;
    if (m == 1) ur[i] = 1;
    for (int j = 1; j < m; j++) {
      p = *v.begin();
      v.erase(v.begin());
      if (prev < p.first) {
        curr++;
        rr[i][p.second] = curr;
      } else {
        rr[i][p.second] = curr;
      }
      if (j == m - 1) {
        ur[i] = curr;
      }
      prev = p.first;
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      v.insert({a[i][j], i});
    }
    pair<int, int> p = *v.begin();
    v.erase(v.begin());
    int prev = p.first;
    int curr = 1;
    rc[p.second][j] = curr;
    if (n == 1) uc[j] = 1;
    for (int i = 1; i < n; i++) {
      p = *v.begin();
      v.erase(v.begin());
      if (prev < p.first) {
        curr++;
        rc[p.second][j] = curr;
      } else {
        rc[p.second][j] = curr;
      }
      if (i == n - 1) {
        uc[j] = curr;
      }
      prev = p.first;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (rr[i][j] <= rc[i][j]) {
        ans[i][j] = max(uc[j], ur[i] + rc[i][j] - rr[i][j]);
      } else
        ans[i][j] = max(ur[i], uc[j] + rr[i][j] - rc[i][j]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
