#include <bits/stdc++.h>
using namespace std;
int N, M;
int input[1001][1001];
vector<int> vt1[1001], vt2[1001];
int main(void) {
  scanf("%d %d", &N, &M);
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      scanf("%d", &input[i][j]);
      vt1[i].push_back(input[i][j]);
      vt2[j].push_back(input[i][j]);
    }
  }
  for (int i = 1; i <= N; i++) {
    sort(vt1[i].begin(), vt1[i].end());
    vt1[i].erase(unique(vt1[i].begin(), vt1[i].end()), vt1[i].end());
  }
  for (int i = 1; i <= M; i++) {
    sort(vt2[i].begin(), vt2[i].end());
    vt2[i].erase(unique(vt2[i].begin(), vt2[i].end()), vt2[i].end());
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      int idx1 = lower_bound(vt1[i].begin(), vt1[i].end(), input[i][j]) -
                 vt1[i].begin();
      int idx2 = lower_bound(vt2[j].begin(), vt2[j].end(), input[i][j]) -
                 vt2[j].begin();
      int res =
          max(idx1, idx2) + 1 +
          max((int)vt1[i].size() - 1 - idx1, (int)vt2[j].size() - 1 - idx2);
      printf("%d ", res);
    }
    printf("\n");
  }
  return 0;
}
