#include <bits/stdc++.h>
const int MAX = 1e3 + 5, INF = 1e9 + 1;
using namespace std;
int n, m, mat[MAX][MAX], difv[MAX], difk[MAX], poz[MAX][MAX][2], rez;
int sorv[MAX], sork[MAX];
pair<int, int> ro[MAX], p1, p2;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf("%i", &mat[i][j]);
    }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) ro[j] = {mat[i][j], j};
    sort(ro + 1, ro + m + 1);
    for (int j = 1; j <= m; j++) {
      if (ro[j].first != ro[j - 1].first) {
        difv[i]++;
      }
      poz[i][ro[j].second][0] = difv[i];
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) ro[j] = {mat[j][i], j};
    sort(ro + 1, ro + n + 1);
    for (int j = 1; j <= n; j++) {
      if (ro[j].first != ro[j - 1].first) {
        difk[i]++;
      }
      poz[ro[j].second][i][1] = difk[i];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      p1 = {difv[i], poz[i][j][0]};
      p2 = {difk[j], poz[i][j][1]};
      if (p1.second > p2.second) swap(p1, p2);
      rez = max(p2.first, p2.second + p1.first - p1.second);
      printf("%i ", rez);
    }
    printf("\n");
  }
  return 0;
}
