#include <bits/stdc++.h>
using namespace std;
const long double PI = acosl(-1.0);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  int a[n][m], ans[n][m];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) cin >> a[i][j];
  vector<map<int, int> > vc1, vc2;
  map<int, int> mymap;
  vector<int> v1, v11, v22;
  for (int i = 0; i < n; i++) {
    mymap.clear();
    v1.clear();
    for (int j = 0; j < m; j++) v1.push_back(a[i][j]);
    sort(v1.begin(), v1.end());
    int k = 1;
    for (int j = 0; j < m; j++) {
      if (mymap.find(v1[j]) == mymap.end()) mymap[v1[j]] = k++;
    }
    v11.push_back(k - 1);
    vc1.push_back(mymap);
  }
  for (int i = 0; i < m; i++) {
    mymap.clear();
    v1.clear();
    for (int j = 0; j < n; j++) v1.push_back(a[j][i]);
    sort(v1.begin(), v1.end());
    int k = 1;
    for (int j = 0; j < n; j++) {
      if (mymap.find(v1[j]) == mymap.end()) mymap[v1[j]] = k++;
    }
    v22.push_back(k - 1);
    vc2.push_back(mymap);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int x = vc1[i][a[i][j]];
      int y = vc2[j][a[i][j]];
      if (x < y)
        ans[i][j] = max(v11[i] + y - x, v22[j]);
      else if (y < x)
        ans[i][j] = max(v11[i], v22[j] + x - y);
      else
        ans[i][j] = max(v11[i], v22[j]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << ans[i][j] << " ";
    cout << "\n";
  }
  return 0;
}
