#include <bits/stdc++.h>
int n, m, a[1005][1005], b[1005], tot, mi[1005][1005], mx[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]);
  for (int i = (1); i <= (n); ++i) {
    for (int j = (1); j <= (m); ++j) b[j] = a[i][j];
    std::sort(b + 1, b + m + 1);
    tot = std::unique(b + 1, b + m + 1) - b - 1;
    for (int j = (1); j <= (m); ++j) {
      int now = std::lower_bound(b + 1, b + tot + 1, a[i][j]) - b;
      mi[i][j] = std::max(mi[i][j], now);
      mx[i][j] = std::max(mx[i][j], tot - now);
    }
  }
  for (int j = (1); j <= (m); ++j) {
    for (int i = (1); i <= (n); ++i) b[i] = a[i][j];
    std::sort(b + 1, b + n + 1);
    tot = std::unique(b + 1, b + n + 1) - b - 1;
    for (int i = (1); i <= (n); ++i) {
      int now = std::lower_bound(b + 1, b + tot + 1, a[i][j]) - b;
      mi[i][j] = std::max(mi[i][j], now);
      mx[i][j] = std::max(mx[i][j], tot - now);
    }
  }
  for (int i = (1); i <= (n); ++i) {
    for (int j = (1); j <= (m); ++j) printf("%d ", mi[i][j] + mx[i][j]);
    puts("");
  }
  return 0;
}
