#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
void unique(vector<int>& v) {
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
}
int n, m, a[1005][1005];
vector<int> col[1005], row[1005];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (m); ++j) {
      cin >> a[i][j];
      row[i].push_back(a[i][j]);
      col[j].push_back(a[i][j]);
    }
  for (int i = (0); i < (n); ++i) unique(row[i]);
  for (int i = (0); i < (m); ++i) unique(col[i]);
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (m); ++j) {
      int lr =
          lower_bound(row[i].begin(), row[i].end(), a[i][j]) - row[i].begin();
      int lc =
          lower_bound(col[j].begin(), col[j].end(), a[i][j]) - col[j].begin();
      cout << (max(lr, lc) + max(row[i].size() - lr, col[j].size() - lc))
           << " \n"[j + 1 == m];
    }
}
