#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(n, vector<int>(m));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> v[i][j];
    }
  }
  vector<vector<int>> unique_by_rows(m, vector<int>());
  for (int j = 0; j < m; ++j) {
    for (int row = 0; row < n; ++row) {
      unique_by_rows[j].push_back(v[row][j]);
    }
    sort(unique_by_rows[j].begin(), unique_by_rows[j].end());
    auto it = unique(unique_by_rows[j].begin(), unique_by_rows[j].end());
    unique_by_rows[j].erase(it, unique_by_rows[j].end());
  }
  vector<vector<int>> unique_by_columns(n, vector<int>());
  for (int i = 0; i < n; ++i) {
    for (int column = 0; column < m; ++column) {
      unique_by_columns[i].push_back(v[i][column]);
    }
    sort(unique_by_columns[i].begin(), unique_by_columns[i].end());
    auto it = unique(unique_by_columns[i].begin(), unique_by_columns[i].end());
    unique_by_columns[i].erase(it, unique_by_columns[i].end());
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int pos_in_rows = lower_bound(unique_by_rows[j].begin(),
                                    unique_by_rows[j].end(), v[i][j]) -
                        unique_by_rows[j].begin();
      int pos_in_cols = lower_bound(unique_by_columns[i].begin(),
                                    unique_by_columns[i].end(), v[i][j]) -
                        unique_by_columns[i].begin();
      if (pos_in_cols > pos_in_rows) {
        cout << max(unique_by_columns[i].size(),
                    unique_by_rows[j].size() + pos_in_cols - pos_in_rows)
             << " ";
      } else {
        cout << max(unique_by_rows[j].size(),
                    unique_by_columns[i].size() + pos_in_rows - pos_in_cols)
             << " ";
      }
    }
    cout << "\n";
  }
  return 0;
}
