#include <bits/stdc++.h>
using namespace std;
template <class myType>
myType revColRow(const myType &vi) {
  myType ret(vi[0].size());
  for (int j = 0; j < vi[0].size(); j++) {
    for (int i = 0; i < vi.size(); i++) {
      ret[j].push_back(vi[i][j]);
    }
  }
  return ret;
}
void solve(const vector<vector<int>> &vi,
           vector<vector<pair<int, int>>> &order) {
  for (int i = 0; i < vi.size(); i++) {
    vector<int> temp;
    for (int j = 0; j < vi[i].size(); j++) {
      temp.push_back(vi[i][j]);
    }
    sort(temp.begin(), temp.end());
    temp.resize(unique(temp.begin(), temp.end()) - temp.begin());
    for (int j = 0; j < vi[i].size(); j++) {
      int val = vi[i][j];
      int idx = find(temp.begin(), temp.end(), val) - temp.begin();
      order[i][j] = {idx, temp.size() - idx - 1};
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<vector<int>> vi(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &vi[i][j]);
    }
  }
  vector<vector<int>> transVi = revColRow<vector<vector<int>>>(vi);
  vector<vector<pair<int, int>>> vecOrder(n, vector<pair<int, int>>(m));
  vector<vector<pair<int, int>>> transVecOrder(m, vector<pair<int, int>>(n));
  solve(vi, vecOrder);
  solve(transVi, transVecOrder);
  transVecOrder = revColRow<vector<vector<pair<int, int>>>>(transVecOrder);
  vector<vector<int>> ans(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      printf("%d ", max(vecOrder[i][j].first, transVecOrder[i][j].first) +
                        max(vecOrder[i][j].second, transVecOrder[i][j].second) +
                        1);
    }
    printf("\n");
  }
  return 0;
}
