#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int n, m, a[N][N], r[N], c[N];
vector<int> row[N], col[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]);
      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());
    r[i] = unique(row[i].begin(), row[i].end()) - row[i].begin();
  }
  for (int i = 1; i <= m; ++i) {
    sort(col[i].begin(), col[i].end());
    c[i] = unique(col[i].begin(), col[i].end()) - col[i].begin();
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      int p = lower_bound(row[i].begin(), row[i].begin() + r[i], a[i][j]) -
              row[i].begin() + 1;
      int q = lower_bound(col[j].begin(), col[j].begin() + c[j], a[i][j]) -
              col[j].begin() + 1;
      int k = max(p, q);
      printf("%d ", k + max(r[i] - p, c[j] - q));
    }
    printf("\n");
  }
}
