#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFLL = 1e18;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;
int n, m;
vector<int> ai[1001];
vector<int> aj[1001];
int maxi[1001];
int maxj[1001];
int A[1001][1001];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int aux;
      scanf("%d", &aux);
      ai[i].push_back(aux);
      aj[j].push_back(aux);
      A[i][j] = aux;
    }
  for (int i = 0; i < n; i++) sort(ai[i].begin(), ai[i].end());
  for (int j = 0; j < m; j++) sort(aj[j].begin(), aj[j].end());
  for (int i = 0; i < n; i++)
    ai[i].resize(distance(ai[i].begin(), unique(ai[i].begin(), ai[i].end())));
  for (int j = 0; j < m; j++)
    aj[j].resize(distance(aj[j].begin(), unique(aj[j].begin(), aj[j].end())));
  for (int i = 0; i < n; i++) maxi[i] = ai[i].size();
  for (int j = 0; j < m; j++) maxj[j] = aj[j].size();
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int posi =
          lower_bound(ai[i].begin(), ai[i].end(), A[i][j]) - ai[i].begin();
      int posj =
          lower_bound(aj[j].begin(), aj[j].end(), A[i][j]) - aj[j].begin();
      if (posi > posj) {
        A[i][j] = max(maxi[i], maxj[j] + (abs(posj - posi)));
      } else {
        A[i][j] = max(maxj[j], maxi[i] + abs(posj - posi));
      }
    }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      printf("%d", A[i][j]);
      if (j != m - 1)
        printf(" ");
      else
        printf("\n");
    }
  }
  return 0;
}
