#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<int> > a, ret;
void go(int r, int c) {
  vector<int> b, d;
  for (int i = 0; i < m; ++i) {
    b.push_back(a[r][i]);
  }
  for (int i = 0; i < n; ++i) {
    d.push_back(a[i][c]);
  }
  sort((b).begin(), (b).end());
  sort((d).begin(), (d).end());
  b.erase(unique((b).begin(), (b).end()), b.end());
  d.erase(unique((d).begin(), (d).end()), d.end());
  int first = lower_bound((b).begin(), (b).end(), a[r][c]) - b.begin();
  int second = lower_bound((d).begin(), (d).end(), a[r][c]) - d.begin();
  ret[r][c] =
      max(first, second) + 1 +
      max(((int)(b).size()) - first - 1, ((int)(d).size()) - second - 1);
}
void solve() {
  cin >> n >> m;
  a = vector<vector<int> >(n, vector<int>(m, 0));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }
  vector<vector<int> > sort_rows = vector<vector<int> >(n);
  for (int i = 0; i < n; ++i) {
    vector<int> b = a[i];
    sort((b).begin(), (b).end());
    b.erase(unique((b).begin(), (b).end()), b.end());
    sort_rows[i] = b;
  }
  vector<vector<int> > sort_cols = vector<vector<int> >(m);
  for (int i = 0; i < m; ++i) {
    vector<int> d;
    for (int k = 0; k < n; ++k) {
      d.push_back(a[k][i]);
    }
    sort((d).begin(), (d).end());
    d.erase(unique((d).begin(), (d).end()), d.end());
    sort_cols[i] = d;
  }
  ret = vector<vector<int> >(n, vector<int>(m, 0));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      vector<int> b = sort_rows[i], d = sort_cols[j];
      int first = lower_bound((b).begin(), (b).end(), a[i][j]) - b.begin();
      int second = lower_bound((d).begin(), (d).end(), a[i][j]) - d.begin();
      ret[i][j] =
          max(first, second) + 1 +
          max(((int)(b).size()) - first - 1, ((int)(d).size()) - second - 1);
    }
  }
  for (int i = 0; i < n; ++i) {
    if (0)
      cout << "ret[i]"
           << ": ";
    for (int second = 0; second < m; ++second) {
      cout << ret[i][second];
      if (second < m - 1) cout << " ";
    }
    cout << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
