#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
int n, m, a[1005][1005];
vector<int> row[1005];
vector<int> col[1005];
int ans[1005][1005];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
      row[i].push_back(a[i][j]);
      col[j].push_back(a[i][j]);
    }
  for (int i = 1; i <= n; i++) {
    sort(row[i].begin(), row[i].end());
    row[i].erase(unique(row[i].begin(), row[i].end()), row[i].end());
  }
  for (int i = 1; i <= m; i++) {
    sort(col[i].begin(), col[i].end());
    col[i].erase(unique(col[i].begin(), col[i].end()), col[i].end());
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int l1 =
          lower_bound(row[i].begin(), row[i].end(), a[i][j]) - row[i].begin();
      int l2 =
          lower_bound(col[j].begin(), col[j].end(), a[i][j]) - col[j].begin();
      int r1 =
          row[i].end() - upper_bound(row[i].begin(), row[i].end(), a[i][j]);
      int r2 =
          col[j].end() - upper_bound(col[j].begin(), col[j].end(), a[i][j]);
      printf("%d ", max(l1, l2) + 1 + max(r1, r2));
    }
    puts("");
  }
  return 0;
}
