#include <bits/stdc++.h>
using namespace std;
int a[1005][1005];
pair<int, int> h[1005][1005], l[1005][1005];
int main() {
  int n, m;
  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++) h[i][j].first = a[i][j];
    sort(h[i] + 1, h[i] + m + 1);
    int rnk = 1;
    for (int j = 1; j <= m; j++) {
      if (h[i][j].first == h[i][j - 1].first)
        h[i][j].second = h[i][j - 1].second;
      else
        h[i][j].second = rnk++;
    }
  }
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++) l[j][i].first = a[i][j];
    sort(l[j] + 1, l[j] + 1 + n);
    int rnk = 1;
    for (int i = 1; i <= n; i++) {
      if (l[j][i].first == l[j][i - 1].first)
        l[j][i].second = l[j][i - 1].second;
      else
        l[j][i].second = rnk++;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      auto it = lower_bound(h[i] + 1, h[i] + 1 + m, pair<int, int>(a[i][j], 0));
      int x = it->second;
      it = lower_bound(l[j] + 1, l[j] + 1 + n, pair<int, int>(a[i][j], 0));
      int y = it->second;
      int ans = 0;
      if (x > y)
        printf("%d", max(h[i][m].second, x + l[j][n].second - y));
      else if (x < y)
        printf("%d", max(l[j][n].second, y + h[i][m].second - x));
      else
        printf("%d", max(h[i][m].second, l[j][n].second));
      if (j != m) printf(" ");
    }
    puts("");
  }
}
