#include <bits/stdc++.h>
using namespace std;
const int N = 1007;
const int INF = 1e9 + 7;
int a[N][N], o[N][N];
int n, m;
set<int> si[N], sj[N];
vector<int> vi[N], vj[N];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
      int ti = si[i].size(), tj = sj[j].size();
      si[i].insert(a[i][j]);
      sj[j].insert(a[i][j]);
      if (ti != si[i].size()) vi[i].push_back(a[i][j]);
      if (tj != sj[j].size()) vj[j].push_back(a[i][j]);
    }
  }
  for (int i = 1; i <= n; i++) sort(vi[i].begin(), vi[i].end());
  for (int i = 1; i <= m; i++) sort(vj[i].begin(), vj[i].end());
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int ci = lower_bound(vi[i].begin(), vi[i].end(), a[i][j]) - vi[i].begin();
      int cj = lower_bound(vj[j].begin(), vj[j].end(), a[i][j]) - vj[j].begin();
      int mn = max(ci, cj);
      int mx = max(si[i].size() - ci - 1, sj[j].size() - cj - 1);
      o[i][j] = mn + mx + 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      printf("%d ", o[i][j]);
    }
    puts("");
  }
}
