#include <bits/stdc++.h>
using namespace std;
const int N = 200043;
int32_t main() {
  int n, m;
  cin >> n >> m;
  int a[n][m];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }
  int h[n][m];
  int ve[n][m];
  int dh[n];
  int dv[m];
  memset(h, 0, sizeof(h));
  memset(ve, 0, sizeof(ve));
  memset(dh, 0, sizeof(dh));
  memset(dv, 0, sizeof(dv));
  for (int i = 0; i < n; ++i) {
    std::vector<int> v;
    for (int j = 0; j < m; ++j) {
      v.push_back(a[i][j]);
    }
    sort(v.begin(), v.end());
    std::vector<int> ne;
    ne.push_back(v[0]);
    for (int j = 1; j < v.size(); ++j) {
      if (v[j] != v[j - 1]) ne.push_back(v[j]);
    }
    for (int j = 0; j < m; ++j) {
      h[i][j] = upper_bound(ne.begin(), ne.end(), a[i][j]) - ne.begin();
    }
    dh[i] = ne.size();
  }
  for (int i = 0; i < m; ++i) {
    std::vector<int> v;
    for (int j = 0; j < n; ++j) {
      v.push_back(a[j][i]);
    }
    sort(v.begin(), v.end());
    std::vector<int> ne;
    ne.push_back(v[0]);
    for (int j = 1; j < v.size(); ++j) {
      if (v[j] != v[j - 1]) ne.push_back(v[j]);
    }
    for (int j = 0; j < n; ++j) {
      ve[j][i] = upper_bound(ne.begin(), ne.end(), a[j][i]) - ne.begin();
    }
    dv[i] = ne.size();
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int x = max(ve[i][j], h[i][j]);
      int l = max(dh[i], dv[j]);
      int p = max(dh[i] - h[i][j], dv[j] - ve[i][j]);
      cout << x + p << " ";
    }
    cout << endl;
  }
  return 0;
}
