#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int a[N][N], r[N][N][2], c[N][N][2];
int n, m;
int xx[N];
int del(int x[], int n) {
  int cnt = 1;
  for (int i = (2); i <= (n); i++)
    if (x[i] != x[cnt]) x[++cnt] = x[i];
  return cnt;
}
void solveR(int k) {
  int cnt = 0;
  for (int i = (1); i <= (m); i++) xx[++cnt] = a[k][i];
  sort(xx + 1, xx + cnt + 1);
  cnt = del(xx, cnt);
  for (int i = (1); i <= (m); i++) {
    r[k][i][0] = lower_bound(xx + 1, xx + cnt + 1, a[k][i]) - xx - 1;
    r[k][i][1] = cnt - r[k][i][0] - 1;
  }
}
void solveC(int k) {
  int cnt = 0;
  for (int i = (1); i <= (n); i++) xx[++cnt] = a[i][k];
  sort(xx + 1, xx + cnt + 1);
  cnt = del(xx, cnt);
  for (int i = (1); i <= (n); i++) {
    c[i][k][0] = lower_bound(xx + 1, xx + cnt + 1, a[i][k]) - xx - 1;
    c[i][k][1] = cnt - c[i][k][0] - 1;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (m); j++) cin >> a[i][j];
  for (int i = (1); i <= (n); i++) solveR(i);
  for (int i = (1); i <= (m); i++) solveC(i);
  for (int i = (1); i <= (n); i++) {
    for (int j = (1); j <= (m); j++)
      printf("%d ",
             max(r[i][j][0], c[i][j][0]) + 1 + max(c[i][j][1], r[i][j][1]));
    puts("");
  }
  return 0;
}
