#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(n, vector<int>(m));
  for (auto &i : v) {
    for (auto &j : i) {
      cin >> j;
    }
  }
  vector<vector<int>> row(n), prefix_row(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      row[i].push_back(v[i][j]);
    }
    sort(row[i].begin(), row[i].end());
    for (int j = 1; j < m; j++) {
      prefix_row[i][j] = prefix_row[i][j - 1];
      if (row[i][j] == row[i][j - 1]) {
        prefix_row[i][j]++;
      }
    }
  }
  vector<vector<int>> column(m), prefix_column(m, vector<int>(n));
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      column[j].push_back(v[i][j]);
    }
    sort(column[j].begin(), column[j].end());
    for (int i = 1; i < n; i++) {
      prefix_column[j][i] = prefix_column[j][i - 1];
      if (column[j][i] == column[j][i - 1]) {
        prefix_column[j][i]++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int pos1 = distance(row[i].begin(),
                          lower_bound(row[i].begin(), row[i].end(), v[i][j])) -
                 prefix_row[i][distance(
                     row[i].begin(),
                     lower_bound(row[i].begin(), row[i].end(), v[i][j]))] +
                 1;
      int pos2 =
          distance(column[j].begin(),
                   lower_bound(column[j].begin(), column[j].end(), v[i][j])) -
          prefix_column[j][distance(
              column[j].begin(),
              lower_bound(column[j].begin(), column[j].end(), v[i][j]))] +
          1;
      int len1 = m - prefix_row[i][m - 1];
      int len2 = n - prefix_column[j][n - 1];
      cout << max(pos1, pos2) + max(0, max(len1 - pos1, len2 - pos2)) << " ";
    }
    cout << endl;
  }
  return 0;
}
