#include <bits/stdc++.h>
using namespace std;
int a[1100][1100], n, m;
int cnt[4][1100][1100];
pair<int, int> t[1100];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) t[j] = make_pair(a[i][j], j);
    sort(t + 1, t + m + 1);
    int allcnt = 0;
    for (int j = 1; j <= m; j++) {
      if (j == 1 || t[j].first != t[j - 1].first) allcnt++;
      cnt[0][i][t[j].second] = allcnt - 1;
    }
    for (int j = 1; j <= m; j++) cnt[1][i][j] = allcnt - cnt[0][i][j];
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) t[j] = make_pair(a[j][i], j);
    sort(t + 1, t + n + 1);
    int allcnt = 0;
    for (int j = 1; j <= n; j++) {
      if (j == 1 || t[j].first != t[j - 1].first) allcnt++;
      cnt[2][t[j].second][i] = allcnt - 1;
    }
    for (int j = 1; j <= n; j++) cnt[3][j][i] = allcnt - cnt[2][j][i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      printf("%d ",
             max(cnt[0][i][j], cnt[2][i][j]) + max(cnt[1][i][j], cnt[3][i][j]));
    putchar('\n');
  }
}
