#include <bits/stdc++.h>
using namespace std;
int N, M;
int A[1024][1024];
int srtL[1024][1024];
int srtC[1024][1024];
int find(int x, int *A) {
  for (int le = 1, ri = A[0]; le <= ri;) {
    int mid = (le + ri) / 2;
    if (A[mid] == x) return mid;
    if (A[mid] < x)
      le = mid + 1;
    else
      ri = mid - 1;
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> N >> M;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++) {
      cin >> A[i][j];
      srtL[i][j] = A[i][j];
      srtC[j][i] = A[i][j];
    }
  for (int i = 1; i <= N; i++) {
    sort(srtL[i] + 1, srtL[i] + M + 1);
    srtL[i][0] = 1;
    for (int j = 2; j <= M; j++)
      if (srtL[i][srtL[i][0]] != srtL[i][j]) srtL[i][++srtL[i][0]] = srtL[i][j];
  }
  for (int i = 1; i <= M; i++) {
    sort(srtC[i] + 1, srtC[i] + N + 1);
    srtC[i][0] = 1;
    for (int j = 2; j <= N; j++)
      if (srtC[i][srtC[i][0]] != srtC[i][j]) srtC[i][++srtC[i][0]] = srtC[i][j];
  }
  for (int i = 1; i <= N; i++, cout << "\n")
    for (int j = 1; j <= M; j++) {
      int posL = find(A[i][j], srtL[i]);
      int posC = find(A[i][j], srtC[j]);
      int maxPos = max(posL, posC);
      cout << max(maxPos - posL + srtL[i][0], maxPos - posC + srtC[j][0])
           << " ";
    }
  return 0;
}
