#include <bits/stdc++.h>
using namespace std;
void print(vector<int> v) {
  vector<int>::iterator it = v.begin();
  while (it != v.end()) {
    cout << *it << " ";
    it++;
  }
  cout << endl;
}
long long hcf(long long n, long long m) {
  if (m == 0) return n;
  if (n < m) swap(n, m);
  return hcf(m, n % m);
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> r(n);
  vector<vector<int>> c(m);
  vector<vector<int>> v(n);
  for (int i = 0; i < n; i++) {
    v[i] = vector<int>(m);
    for (int j = 0; j < m; j++) {
      cin >> v[i][j];
    }
    vector<int> row(v[i].begin(), v[i].end());
    sort(row.begin(), row.end());
    row.erase(unique(row.begin(), row.end()), row.end());
    r[i] = row;
  }
  for (int j = 0; j < m; j++) {
    vector<int> col;
    for (int i = 0; i < n; i++) {
      col.push_back(v[i][j]);
    }
    sort(col.begin(), col.end());
    col.erase(unique(col.begin(), col.end()), col.end());
    c[j] = col;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int w, x, y, z;
      w = lower_bound(r[i].begin(), r[i].end(), v[i][j]) - r[i].begin();
      x = r[i].size() - w;
      y = lower_bound(c[j].begin(), c[j].end(), v[i][j]) - c[j].begin();
      z = c[j].size() - y;
      cout << max(w, y) + max(x, z) << " ";
    }
    cout << endl;
  }
}
