#include <bits/stdc++.h>
using namespace std;
int n, m, a[1010][1010];
int l[1010][1010], r[1010][1010];
int id[1010];
int Col, Row;
bool cmp_row(int i, int j) { return a[Row][i] < a[Row][j]; }
bool cmp_col(int i, int j) { return a[i][Col] < a[j][Col]; }
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 (Row = 1; Row <= n; Row++) {
    for (int j = 1; j <= m; j++) id[j] = j;
    sort(id + 1, id + m + 1, cmp_row);
    for (int j = 1, k = 1, cnt = 0; j <= m; j++) {
      if (a[Row][id[j]] != a[Row][id[k]]) k = j, cnt++;
      l[Row][id[j]] = cnt;
    }
    for (int j = m, k = m, cnt = 0; j >= 1; j--) {
      if (a[Row][id[j]] != a[Row][id[k]]) k = j, cnt++;
      r[Row][id[j]] = cnt;
    }
  }
  for (Col = 1; Col <= m; Col++) {
    for (int i = 1; i <= n; i++) id[i] = i;
    sort(id + 1, id + n + 1, cmp_col);
    for (int i = 1, k = 1, cnt = 0; i <= n; i++) {
      if (a[id[i]][Col] != a[id[k]][Col]) k = i, cnt++;
      l[id[i]][Col] = max(l[id[i]][Col], cnt);
    }
    for (int i = n, k = n, cnt = 0; i >= 1; i--) {
      if (a[id[i]][Col] != a[id[k]][Col]) k = i, cnt++;
      r[id[i]][Col] = max(r[id[i]][Col], cnt);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) printf("%d ", l[i][j] + r[i][j] + 1);
    putchar('\n');
  }
}
