#include <bits/stdc++.h>
using namespace std;
const long long N = 1e3 + 103;
const long long mod = 1e9 + 7;
const long long inf = 1e18 + 3;
long long mat[N][N];
void testcase() {
  long long n, m;
  cin >> n >> m;
  vector<set<long long>> ROW(n + 1);
  vector<set<long long>> COL(m + 1);
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> mat[i][j];
      COL[j + 1].insert(mat[i][j]);
      ROW[i + 1].insert(mat[i][j]);
    }
  }
  vector<map<long long, long long>> Row_wise_pos(n + 1);
  vector<map<long long, long long>> Col_wise_pos(m + 1);
  for (long long i = 1; i <= n; i++) {
    vector<long long> temp;
    while (ROW[i].size()) {
      long long val = *ROW[i].begin();
      ROW[i].erase(val);
      temp.push_back(val);
    }
    for (long long j = 0; j < temp.size(); j++) {
      Row_wise_pos[i][temp[j]] = j + 1;
    }
  }
  for (long long j = 1; j <= m; j++) {
    vector<long long> temp;
    while (COL[j].size()) {
      long long val = *COL[j].begin();
      COL[j].erase(val);
      temp.push_back(val);
    }
    for (long long i = 0; i < temp.size(); i++) {
      Col_wise_pos[j][temp[i]] = i + 1;
    }
  }
  auto cal = [&](long long ele, long long row, long long col) {
    long long row_val = Row_wise_pos[row][ele];
    long long col_val = Col_wise_pos[col][ele];
    long long common = max(row_val, col_val);
    long long extra = max(Row_wise_pos[row].size() - row_val,
                          Col_wise_pos[col].size() - col_val);
    return (common + extra);
  };
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cout << cal(mat[i][j], i + 1, j + 1) << " ";
    }
    cout << "\n";
  }
  return;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) {
    testcase();
  }
  return 0;
}
