#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int ara[n + 5][m + 5];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> ara[i][j];
    }
  }
  vector<int> vr[n + 5], vc[m + 5];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      vr[i].push_back(ara[i][j]);
    }
    sort(vr[i].begin(), vr[i].end());
    vr[i].erase(unique(vr[i].begin(), vr[i].end()), vr[i].end());
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      vc[i].push_back(ara[j][i]);
    }
    sort(vc[i].begin(), vc[i].end());
    vc[i].erase(unique(vc[i].begin(), vc[i].end()), vc[i].end());
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int xi =
          lower_bound(vr[i].begin(), vr[i].end(), ara[i][j]) - vr[i].begin();
      int yi =
          lower_bound(vc[j].begin(), vc[j].end(), ara[i][j]) - vc[j].begin();
      int interi = max(xi, yi);
      int intere = max(vr[i].size() - xi, vc[j].size() - yi);
      cout << intere + interi << ' ';
    }
    cout << endl;
  }
}
