#include <bits/stdc++.h>
using namespace std;
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p) {
  return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc) {
  o << "{";
  for (const T& v : vc) o << v << ",";
  o << "}";
  return o;
}
using ll = long long;
template <class T>
using V = vector<T>;
template <class T>
using VV = vector<vector<T>>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  VV<int> a(H, V<int>(W));
  for (int i = 0; i < (int)(H); i++)
    for (int j = 0; j < (int)(W); j++) cin >> a[i][j];
  VV<int> x(H, V<int>(W));
  VV<int> y(H, V<int>(W));
  V<int> mx(H), my(W);
  for (int i = 0; i < (int)(H); i++) {
    V<int> as;
    for (int j = 0; j < (int)(W); j++) as.push_back(a[i][j]);
    sort(as.begin(), as.end());
    as.erase(unique(as.begin(), as.end()), as.end());
    for (int j = 0; j < (int)(W); j++)
      x[i][j] = lower_bound(as.begin(), as.end(), a[i][j]) - as.begin();
    mx[i] = as.size();
  }
  for (int j = 0; j < (int)(W); j++) {
    V<int> as;
    for (int i = 0; i < (int)(H); i++) as.push_back(a[i][j]);
    sort(as.begin(), as.end());
    as.erase(unique(as.begin(), as.end()), as.end());
    for (int i = 0; i < (int)(H); i++)
      y[i][j] = lower_bound(as.begin(), as.end(), a[i][j]) - as.begin();
    my[j] = as.size();
  }
  for (int i = 0; i < (int)(H); i++) {
    for (int j = 0; j < (int)(W); j++) {
      auto calc = [&](int a, int A, int b, int B) {
        return max(a, b) + max(A - a, B - b);
      };
      cout << calc(x[i][j], mx[i], y[i][j], my[j]) << " ";
    }
    cout << endl;
  }
}
