#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[1000][1000];
vector<int> b[1000], c[1000];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) cin >> a[i][j];
  for (int i = 0; i < n; ++i) {
    c[i].resize(m);
    for (int j = 0; j < m; ++j) c[i][j] = a[i][j];
    sort(c[i].begin(), c[i].end());
    c[i].erase(unique(c[i].begin(), c[i].end()), c[i].end());
  }
  for (int j = 0; j < m; ++j) {
    b[j].resize(n);
    for (int i = 0; i < n; ++i) b[j][i] = a[i][j];
    sort(b[j].begin(), b[j].end());
    b[j].erase(unique(b[j].begin(), b[j].end()), b[j].end());
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int t = lower_bound(c[i].begin(), c[i].end(), a[i][j]) - c[i].begin();
      int r = lower_bound(b[j].begin(), b[j].end(), a[i][j]) - b[j].begin();
      cout << max(t, r) + max(((int)c[i].size()) - t, ((int)b[j].size()) - r)
           << ' ';
    }
    cout << '\n';
  }
  return 0;
}
