#include <bits/stdc++.h>
const double pi = 4.0 * atan(1.0);
const double e = exp(1.0);
const int maxn = 1e5 + 8;
const long long mod = 1e9 + 7;
const unsigned long long base = 1e7 + 7;
using namespace std;
int a[2][1008][1008];
pair<int, int> s[1008][1008];
pair<int, int> t[1008][1008];
int h[1008], l[1008];
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", &s[i][j].first);
      s[i][j].second = j;
      t[j][i].first = s[i][j].first;
      t[j][i].second = i;
    }
  }
  for (int i = 1; i <= n; i++) {
    sort(s[i] + 1, s[i] + 1 + m);
    int cnt = 0;
    for (int j = 1; j <= m; j++) {
      if (s[i][j].first != s[i][j - 1].first) {
        cnt++;
      }
      a[0][i][s[i][j].second] = cnt;
    }
    h[i] = cnt;
  }
  for (int j = 1; j <= m; j++) {
    sort(t[j] + 1, t[j] + 1 + n);
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
      if (t[j][i].first != t[j][i - 1].first) {
        cnt++;
      }
      a[1][t[j][i].second][j] = cnt;
    }
    l[j] = cnt;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int ans = max(h[i], l[j]);
      if (a[0][i][j] > a[1][i][j]) {
        ans = max(ans, l[j] + a[0][i][j] - a[1][i][j]);
      } else {
        ans = max(ans, h[i] + a[1][i][j] - a[0][i][j]);
      }
      printf("%d ", ans);
    }
    printf("\n");
  }
}
