#include <bits/stdc++.h>
int n, m, z[1005][1005], a[1005][1005], b[1005][1005], tpa[1005], tpb[1005];
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (m); ++j) cin >> z[i][j], a[i][j] = b[j][i] = z[i][j];
  for (int i = 0; i < (n); ++i)
    sort(a[i], a[i] + m), tpa[i] = unique(a[i], a[i] + m) - a[i];
  for (int i = 0; i < (m); ++i)
    sort(b[i], b[i] + n), tpb[i] = unique(b[i], b[i] + n) - b[i];
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (m); ++j) {
      int aa = lower_bound(a[i], a[i] + tpa[i], z[i][j]) - a[i];
      int bb = lower_bound(b[j], b[j] + tpb[j], z[i][j]) - b[j];
      cout << max(aa, bb) + max(tpa[i] - aa, tpb[j] - bb) << " \n"[j == m - 1];
    }
  return 0;
}
