#include <bits/stdc++.h>
using namespace std;
int row, column;
int table[1005][1005];
int new_row[1005], spot_row[1005][1005], unique_row[1005];
int new_col[1005], spot_col[1005][1005], unique_col[1005];
void solve() {
  for (int i = 1; i <= row; i++) {
    for (int j = 1; j <= column; j++) new_row[j] = table[i][j];
    sort(new_row + 1, new_row + column + 1);
    unique_row[i] = unique(new_row + 1, new_row + column + 1) - new_row - 1;
    for (int j = 1; j <= column; j++)
      spot_row[i][j] =
          lower_bound(new_row + 1, new_row + unique_row[i] + 1, table[i][j]) -
          new_row;
  }
  for (int j = 1; j <= column; j++) {
    for (int i = 1; i <= row; i++) new_col[i] = table[i][j];
    sort(new_col + 1, new_col + row + 1);
    unique_col[j] = unique(new_col + 1, new_col + row + 1) - new_col - 1;
    for (int i = 1; i <= row; i++)
      spot_col[i][j] =
          lower_bound(new_col + 1, new_col + unique_col[j] + 1, table[i][j]) -
          new_col;
  }
  for (int i = 1; i <= row; i++) {
    for (int j = 1; j <= column; j++)
      printf("%d ", max(spot_row[i][j], spot_col[i][j]) +
                        max(unique_row[i] - spot_row[i][j],
                            unique_col[j] - spot_col[i][j]));
    printf("\n");
  }
}
int main() {
  scanf("%d %d", &row, &column);
  for (int i = 1; i <= row; i++)
    for (int j = 1; j <= column; j++) scanf("%d", &table[i][j]);
  solve();
}
