#include <bits/stdc++.h>
using namespace std;
map<long long, int> row[2000], col[2000];
long long a[2000][2000];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      scanf("%d", &a[i][j]), row[i][a[i][j]], col[j][a[i][j]];
  for (int i = 0; i < n; i++) {
    int cnt = 1;
    for (auto x : row[i]) row[i][x.first] = cnt++;
  }
  for (int j = 0; j < m; j++) {
    int cnt = 1;
    for (auto x : col[j]) col[j][x.first] = cnt++;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int nrow = (int)row[i].size();
      int ncol = (int)col[j].size();
      int valrow = row[i][a[i][j]];
      int valcol = col[j][a[i][j]];
      printf("%d ", max(abs(valrow - valcol) + (valrow < valcol ? nrow : ncol),
                        (valrow < valcol ? ncol : nrow)));
    }
    printf("\n");
  }
  return 0;
}
