#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int a[1005][1005];
int x[1005][1005], y[1005][1005], cx[1005], cy[1005];
pair<int, int> b[1005];
int main() {
  int n, m, i, j, k, t;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  memset(y, 127, sizeof(y));
  memset(x, 127, sizeof(x));
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) b[j].first = a[i][j], b[j].second = j;
    sort(b + 1, b + m + 1);
    k = 0;
    for (j = 1; j <= m; j++) {
      if (j == 1 || b[j].first > b[j - 1].first) k++;
      x[i][b[j].second] = k;
    }
    cx[i] = k;
  }
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= n; j++) b[j].first = a[j][i], b[j].second = j;
    sort(b + 1, b + n + 1);
    k = 0;
    for (j = 1; j <= n; j++) {
      if (j == 1 || b[j].first > b[j - 1].first) k++;
      y[b[j].second][i] = k;
    }
    cy[i] = k;
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      printf("%d ",
             max(x[i][j], y[i][j]) + max(cx[i] - x[i][j], cy[j] - y[i][j]));
    }
    printf("\n");
  }
  return 0;
}
