#include <bits/stdc++.h>
using namespace std;
static const int maxn = 1100;
pair<int, int> a[maxn][maxn];
pair<int, int> b[maxn][maxn];
pair<int, int> c[maxn][maxn];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, m;
  cin >> n >> m;
  for (int x, i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> x;
      b[j][i].first = a[i][j].first = x;
      a[i][j].second = j;
      b[j][i].second = i;
    }
  }
  for (int i = 0; i < n; ++i) {
    sort(a[i], a[i] + m);
    int k = 0;
    int prev = a[i][0].first + 1;
    for (int j = 0; j < m; ++j) {
      c[i][a[i][j].second].first = prev == a[i][j].first ? k : ++k;
      prev = a[i][j].first;
    }
    a[i][0].first = k;
  }
  for (int j = 0; j < m; ++j) {
    sort(b[j], b[j] + n);
    int k = 0;
    int prev = b[j][0].first + 1;
    for (int i = 0; i < n; ++i) {
      c[b[j][i].second][j].second = prev == b[j][i].first ? k : ++k;
      prev = b[j][i].first;
    }
    b[j][0].first = k;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int ans = max(c[i][j].first, c[i][j].second) + 1 +
                max(a[i][0].first - c[i][j].first - 1,
                    b[j][0].first - c[i][j].second - 1);
      cout << ans << ' ';
    }
    cout << '\n';
  }
}
