#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cout << *it << " = " << a << endl;
  err(++it, args...);
}
const long long mod = (long long)1e9 + 7;
const long long MOD = (long long)998244353;
const long long INF = (long long)1e18;
inline long long add(long long a, long long b) {
  return (a + b >= mod ? a + b - mod : a + b);
}
inline long long mul(long long a, long long b) {
  return (long long)a * b % mod;
}
void solve() {
  long long n, m;
  cin >> n >> m;
  long long a[n][m];
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n)))
    for (__typeof(m) j = (0) - ((0) > (m)); j != (m) - ((0) > (m));
         j += 1 - 2 * ((0) > (m)))
      cin >> a[i][j];
  set<long long> compR[n], compC[m];
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j < m; ++j) {
      compR[i].insert(a[i][j]);
    }
  }
  for (long long j = 0; j < m; ++j) {
    for (long long i = 0; i < n; ++i) {
      compC[j].insert(a[i][j]);
    }
  }
  vector<long long> v1[n], v2[m];
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n)))
    for (auto j : compR[i]) v1[i].push_back(j);
  for (__typeof(m) j = (0) - ((0) > (m)); j != (m) - ((0) > (m));
       j += 1 - 2 * ((0) > (m)))
    for (auto i : compC[j]) v2[j].push_back(i);
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n))) {
    for (__typeof(m) j = (0) - ((0) > (m)); j != (m) - ((0) > (m));
         j += 1 - 2 * ((0) > (m))) {
      long long f =
          lower_bound((v1[i]).begin(), (v1[i]).end(), a[i][j]) - v1[i].begin();
      long long s =
          lower_bound((v2[j]).begin(), (v2[j]).end(), a[i][j]) - v2[j].begin();
      long long rf = (long long)(v1[i]).size() - f - 1;
      long long rs = (long long)(v2[j]).size() - s - 1;
      cout << 1 + max(f, s) + max(rf, rs) << " ";
    }
    cout << "\n";
  }
}
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  solve();
  return 0;
}
