#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int a[N][N], n, m;
vector<int> r[N], c[N];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
  for (int i = 0; i < n; i++) {
    r[i].resize(m);
    for (int j = 0; j < m; j++) r[i][j] = a[i][j];
    sort(r[i].begin(), r[i].end());
    r[i].erase(unique(r[i].begin(), r[i].end()), r[i].end());
  }
  for (int j = 0; j < m; j++) {
    c[j].resize(n);
    for (int i = 0; i < n; i++) c[j][i] = a[i][j];
    sort(c[j].begin(), c[j].end());
    c[j].erase(unique(c[j].begin(), c[j].end()), c[j].end());
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int Lr = lower_bound(r[i].begin(), r[i].end(), a[i][j]) - r[i].begin();
      int Lc = lower_bound(c[j].begin(), c[j].end(), a[i][j]) - c[j].begin();
      int Gr = r[i].end() - lower_bound(r[i].begin(), r[i].end(), a[i][j]);
      int Gc = c[j].end() - lower_bound(c[j].begin(), c[j].end(), a[i][j]);
      printf("%d ", max(Lc, Lr) + max(Gc, Gr));
    }
    printf("\n");
  }
  return 0;
}
