#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int tab[maxn][maxn];
vector<int> row[maxn], col[maxn];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &tab[i][j]);
      int x = tab[i][j];
      row[i].emplace_back(x);
      col[j].emplace_back(x);
    }
  }
  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 a =
          lower_bound(row[i].begin(), row[i].end(), tab[i][j]) - row[i].begin();
      int b =
          lower_bound(col[j].begin(), col[j].end(), tab[i][j]) - col[j].begin();
      int c =
          row[i].end() - lower_bound(row[i].begin(), row[i].end(), tab[i][j]);
      int d =
          col[j].end() - lower_bound(col[j].begin(), col[j].end(), tab[i][j]);
      printf("%d ", max(a, b) + max(c, d));
    }
    printf("\n");
  }
}
