#include <bits/stdc++.h>
int main() {
  int n, m;
  std::cin >> n >> m;
  int x[1001][1001];
  std::vector<int> e[1001];
  std::vector<int> s[1001];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int k;
      std::cin >> k;
      x[i][j] = k;
      e[i].push_back(k);
      s[j].push_back(k);
    }
    std::sort(e[i].begin(), e[i].end());
    e[i].resize(std::unique(e[i].begin(), e[i].end()) - e[i].begin());
  }
  for (int j = 0; j < m; j++) {
    std::sort(s[j].begin(), s[j].end());
    s[j].resize(std::unique(s[j].begin(), s[j].end()) - s[j].begin());
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int common = x[i][j];
      int eLess =
          std::lower_bound(e[i].begin(), e[i].end(), common) - e[i].begin();
      int eGreater = e[i].size() - 1 - eLess;
      int sLess =
          std::lower_bound(s[j].begin(), s[j].end(), common) - s[j].begin();
      int sGreater = s[j].size() - 1 - sLess;
      std::cout << std::max(eLess, sLess) + 1 + std::max(eGreater, sGreater)
                << " ";
    }
    std::cout << "\n";
  }
  return 0;
}
