#include <bits/stdc++.h>
using namespace std;
void upgrade() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
}
int main() {
  int a[1000][1000];
  vector<int> across[1000];
  vector<int> down[1000];
  upgrade();
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  for (int i = 0; i < n; i++) {
    vector<int> temp(1, 0);
    for (int j = 0; j < m; j++) temp.push_back(a[i][j]);
    sort((temp).begin(), (temp).end());
    for (int j = 1; j < m + 1; j++)
      if (temp[j] != temp[j - 1]) across[i].push_back(temp[j]);
  }
  for (int i = 0; i < m; i++) {
    vector<int> temp(1, 0);
    for (int j = 0; j < n; j++) temp.push_back(a[j][i]);
    sort((temp).begin(), (temp).end());
    for (int j = 1; j < n + 1; j++)
      if (temp[j] != temp[j - 1]) down[i].push_back(temp[j]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int num = a[i][j];
      int p1 = lower_bound((across[i]).begin(), (across[i]).end(), num) -
               across[i].begin();
      int p2 = lower_bound((down[j]).begin(), (down[j]).end(), num) -
               down[j].begin();
      int mx = max(p1, p2);
      cout << max(mx + (int)(across[i]).size() - p1,
                  mx + (int)(down[j]).size() - p2)
           << ' ';
    }
    cout << '\n';
  }
}
