#include <bits/stdc++.h>
using namespace std;
void read(int& x) { scanf("%d", &x); }
void read(long long& x) { scanf("%lld", &x); }
void read(pair<int, int>& x) { scanf("%d%d", &x.first, &x.second); }
void read(pair<long long, long long>& x) {
  scanf("%lld%lld", &x.first, &x.second);
}
template <typename T, typename... Args>
void read(T& a, Args&... b) {
  read(a);
  read(b...);
}
void cppio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
int a[1010][1010];
int n, m;
int rnkr[1010][1010];
int rnkc[1010][1010];
int sr[1010], sc[1010];
int main() {
  cppio();
  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) {
    vector<int> v;
    for (int j = 1; j <= (m); ++j) v.push_back(a[i][j]);
    sort((v).begin(), (v).end());
    v.erase(unique((v).begin(), (v).end()), v.end());
    sr[i] = v.size();
    for (int j = 1; j <= (m); ++j) {
      rnkr[i][j] = lower_bound((v).begin(), (v).end(), a[i][j]) - v.begin() + 1;
    }
  }
  for (int j = 1; j <= (m); ++j) {
    vector<int> v;
    for (int i = 1; i <= (n); ++i) v.push_back(a[i][j]);
    sort((v).begin(), (v).end());
    v.erase(unique((v).begin(), (v).end()), v.end());
    sc[j] = v.size();
    for (int i = 1; i <= (n); ++i) {
      rnkc[i][j] = lower_bound((v).begin(), (v).end(), a[i][j]) - v.begin() + 1;
    }
  }
  for (int i = 1; i <= (n); ++i) {
    for (int j = 1; j <= (m); ++j) {
      cout << max(rnkr[i][j], rnkc[i][j]) +
                  max(sr[i] - rnkr[i][j], sc[j] - rnkc[i][j])
           << ' ';
    }
    cout << '\n';
  }
  return 0;
}
