#include <bits/stdc++.h>
const long long MAX_N = 1007;
long long n, m, grid[MAX_N][MAX_N];
std::map<long long, long long> coord;
long long rank[4][MAX_N][MAX_N];
int main(void) {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  std::cin >> n >> m;
  for (long long i = 0; i < n; ++i)
    for (long long j = 0; j < m; ++j) std::cin >> grid[i][j];
  {
    for (long long i = 0; i < n; ++i) {
      std::vector<long long> vals(m);
      for (long long j = 0; j < m; ++j) vals[j] = grid[i][j];
      std::sort(vals.begin(), vals.end());
      vals.erase(std::unique(vals.begin(), vals.end()), vals.end());
      for (long long j = 0; j < m; ++j) {
        rank[0][i][j] = std::distance(
            vals.begin(),
            std::lower_bound(vals.begin(), vals.end(), grid[i][j]));
        rank[1][i][j] = std::distance(
            std::upper_bound(vals.begin(), vals.end(), grid[i][j]), vals.end());
      }
    }
  }
  {
    for (long long j = 0; j < m; ++j) {
      std::vector<long long> vals(n);
      for (long long i = 0; i < n; ++i) vals[i] = grid[i][j];
      std::sort(vals.begin(), vals.end());
      vals.erase(std::unique(vals.begin(), vals.end()), vals.end());
      for (long long i = 0; i < n; ++i) {
        rank[2][i][j] = std::distance(
            vals.begin(),
            std::lower_bound(vals.begin(), vals.end(), grid[i][j]));
        rank[3][i][j] = std::distance(
            std::upper_bound(vals.begin(), vals.end(), grid[i][j]), vals.end());
      }
    }
  }
  for (long long i = 0; i < n; ++i)
    for (long long j = 0; j < m; ++j)
      std::cout << (1 + std::max(rank[0][i][j], rank[2][i][j]) +
                    std::max(rank[1][i][j], rank[3][i][j]))
                << " \n"[j + 1 == m];
  return 0;
}
