#include <bits/stdc++.h>
using namespace std;
int n, m;
pair<int, int> tmp[1005];
int a[1005][1005];
int rawIdx[1005][1005];
int columnIdx[1005][1005];
int rawMax[1005], columnMax[1005];
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> a[i][j];
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      tmp[j] = make_pair(a[i][j], j);
    }
    sort(tmp + 1, tmp + m + 1);
    int idx = 0;
    for (int j = 1; j <= m; ++j) {
      if (tmp[j].first != tmp[j - 1].first) ++idx;
      rawIdx[i][tmp[j].second] = idx;
    }
    rawMax[i] = idx;
  }
  for (int j = 1; j <= m; ++j) {
    for (int i = 1; i <= n; ++i) {
      tmp[i] = make_pair(a[i][j], i);
    }
    sort(tmp + 1, tmp + n + 1);
    int idx = 0;
    for (int i = 1; i <= n; ++i) {
      if (tmp[i].first != tmp[i - 1].first) ++idx;
      columnIdx[tmp[i].second][j] = idx;
    }
    columnMax[j] = idx;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      int ans;
      if (rawIdx[i][j] > columnIdx[i][j]) {
        int delta = rawIdx[i][j] - columnIdx[i][j];
        ans = max(rawMax[i], columnMax[j] + delta);
      } else {
        int delta = columnIdx[i][j] - rawIdx[i][j];
        ans = max(rawMax[i] + delta, columnMax[j]);
      }
      cout << ans << " ";
    }
    cout << '\n';
  }
  return 0;
}
