#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
void pre() {}
void solve() {}
int a[1009][1009], b[1009][1009][2];
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  pre();
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (m); ++j) cin >> a[i][j];
  for (int i = 0; i < (n); ++i) {
    vector<int> cur;
    for (int j = 0; j < (m); ++j) cur.push_back(a[i][j]);
    sort(cur.begin(), cur.end());
    cur.resize(distance(cur.begin(), unique(cur.begin(), cur.end())));
    for (int j = 0; j < (m); ++j) {
      b[i][j][0] = lower_bound(cur.begin(), cur.end(), a[i][j]) - cur.begin();
      b[i][j][1] = (int)(cur).size() -
                   (upper_bound(cur.begin(), cur.end(), a[i][j]) - cur.begin());
    }
  }
  for (int j = 0; j < (m); ++j) {
    vector<int> cur;
    for (int i = 0; i < (n); ++i) cur.push_back(a[i][j]);
    sort(cur.begin(), cur.end());
    cur.resize(distance(cur.begin(), unique(cur.begin(), cur.end())));
    for (int i = 0; i < (n); ++i) {
      b[i][j][0] =
          max(b[i][j][0],
              int(lower_bound(cur.begin(), cur.end(), a[i][j]) - cur.begin()));
      b[i][j][1] = max(
          b[i][j][1],
          (int)(cur).size() -
              int(upper_bound(cur.begin(), cur.end(), a[i][j]) - cur.begin()));
    }
  }
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (m); ++j) cout << b[i][j][0] + b[i][j][1] + 1 << ' ';
    cout << '\n';
  }
  return 0;
}
