#include <bits/stdc++.h>
using namespace std;
struct dta {
  int val, id;
  dta(int _val = 0, int _id = 0) {
    val = _val;
    id = _id;
  }
};
inline bool operator<(const dta &a, const dta &b) { return (a.val < b.val); }
int n, m, A[1010][1010], val[2][1010][1010], maxx[2][1010];
vector<dta> tmp;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  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) {
    tmp.clear();
    for (int j = 1; j <= m; ++j) tmp.push_back(dta(A[i][j], j));
    sort(tmp.begin(), tmp.end());
    val[0][i][tmp[0].id] = 1;
    for (int j = 2; j <= m; ++j)
      val[0][i][tmp[j - 1].id] = (tmp[j - 1].val != tmp[j - 2].val)
                                     ? (val[0][i][tmp[j - 2].id] + 1)
                                     : (val[0][i][tmp[j - 2].id]);
    maxx[0][i] = val[0][i][tmp.back().id];
  }
  for (int j = 1; j <= m; ++j) {
    tmp.clear();
    for (int i = 1; i <= n; ++i) tmp.push_back(dta(A[i][j], i));
    sort(tmp.begin(), tmp.end());
    val[1][tmp[0].id][j] = 1;
    for (int i = 2; i <= n; ++i)
      val[1][tmp[i - 1].id][j] = (tmp[i - 1].val != tmp[i - 2].val)
                                     ? (val[1][tmp[i - 2].id][j] + 1)
                                     : (val[1][tmp[i - 2].id][j]);
    maxx[1][j] = val[1][tmp.back().id][j];
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (val[0][i][j] < val[1][i][j])
        cout << max(maxx[0][i] + val[1][i][j] - val[0][i][j], maxx[1][j])
             << ' ';
      else
        cout << max(maxx[1][j] + val[0][i][j] - val[1][i][j], maxx[0][i])
             << ' ';
    }
    cout << "\n";
  }
  return 0;
}
