#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
int n, m;
int grid[1005][1005];
int gtrn[1005][1005];
int horiz[1005][1005];
int vert[1005][1005];
int unhor[1005];
int unver[1005];
vector<int> vals;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < (signed)(n); i++) {
    for (int j = 0; j < (signed)(m); j++) {
      cin >> grid[i][j];
      gtrn[j][i] = grid[i][j];
    }
  }
  for (int i = 0; i < (signed)(n); i++) {
    vals.clear();
    for (int j = 0; j < (signed)(m); j++) {
      vals.push_back(grid[i][j]);
    }
    sort(vals.begin(), vals.end());
    vector<int>::iterator it = unique(vals.begin(), vals.end());
    vals.resize(distance(vals.begin(), it));
    for (int j = 0; j < (signed)(m); j++) {
      horiz[i][j] =
          lower_bound(vals.begin(), vals.end(), grid[i][j]) - vals.begin();
    }
    unhor[i] = vals.size();
  }
  for (int j = 0; j < (signed)(m); j++) {
    vals.clear();
    for (int i = 0; i < (signed)(n); i++) {
      vals.push_back(grid[i][j]);
    }
    sort(vals.begin(), vals.end());
    vector<int>::iterator it = unique(vals.begin(), vals.end());
    vals.resize(distance(vals.begin(), it));
    for (int i = 0; i < (signed)(n); i++) {
      vert[i][j] =
          lower_bound(vals.begin(), vals.end(), grid[i][j]) - vals.begin();
    }
    unver[j] = vals.size();
  }
  for (int i = 0; i < (signed)(n); i++) {
    for (int j = 0; j < (signed)(m); j++) {
      int b4 = max(vert[i][j], horiz[i][j]);
      int aft = max(unhor[i] - horiz[i][j], unver[j] - vert[i][j]);
      cout << b4 + aft << " ";
    }
    cout << "\n";
  }
  return 0;
}
