#include <bits/stdc++.h>
using namespace std;
const int maxN = 1005;
int N, M;
int a[maxN][maxN];
vector<int> row[maxN], col[maxN];
int main() {
  cin >> N >> M;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= M; ++j) {
      scanf("%d", &a[i][j]);
      row[i].push_back(a[i][j]);
      col[j].push_back(a[i][j]);
    }
  }
  for (int i = 1; i <= N; ++i) {
    sort(row[i].begin(), row[i].end());
    row[i].resize(unique(row[i].begin(), row[i].end()) - row[i].begin());
  }
  for (int i = 1; i <= M; ++i) {
    sort(col[i].begin(), col[i].end());
    col[i].resize(unique(col[i].begin(), col[i].end()) - col[i].begin());
  }
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= M; ++j) {
      int ans = max(int(lower_bound(row[i].begin(), row[i].end(), a[i][j]) -
                        row[i].begin()),
                    int(lower_bound(col[j].begin(), col[j].end(), a[i][j]) -
                        col[j].begin())) +
                max(int((row[i]).size() -
                        int(lower_bound(row[i].begin(), row[i].end(), a[i][j]) -
                            row[i].begin())),
                    int((col[j]).size() -
                        int(lower_bound(col[j].begin(), col[j].end(), a[i][j]) -
                            col[j].begin())));
      printf(j == M ? "%d\n" : "%d ", ans);
    }
  }
  return 0;
}
