#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[1001][1001];
int sorted_row[1001][1001];
int sorted_col[1001][1001];
int max_row[1001];
int max_col[1001];
void sr(int idx) {
  priority_queue<int> pq;
  map<int, int> mp;
  for (int i = 0; i < m; i++) {
    pq.push(-a[idx][i]);
  }
  int cnt = 0;
  int x;
  while (!pq.empty()) {
    x = -pq.top();
    if (mp[x] == 0) {
      mp[x] = ++cnt;
    }
    pq.pop();
  }
  max_row[idx] = cnt;
  for (int i = 0; i < m; i++) {
    sorted_row[idx][i] = mp[a[idx][i]];
  }
}
void sc(int idx) {
  priority_queue<int> pq;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    pq.push(-a[i][idx]);
  }
  int cnt = 0;
  int x;
  while (!pq.empty()) {
    x = -pq.top();
    if (mp[x] == 0) {
      mp[x] = ++cnt;
    }
    pq.pop();
  }
  max_col[idx] = cnt;
  for (int i = 0; i < n; i++) {
    sorted_col[i][idx] = mp[a[i][idx]];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    sr(i);
  }
  for (int i = 0; i < m; i++) sc(i);
  int r, c, mx;
  int ans;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      r = sorted_row[i][j];
      c = sorted_col[i][j];
      if (r > c) {
        ans = max_row[i];
        ans = max(ans, max_col[j] + (r - c));
        cout << ans << ' ';
      } else {
        ans = max_col[j];
        ans = max(ans, max_row[i] + (c - r));
        cout << ans << ' ';
      }
    }
    cout << endl;
  }
  return 0;
}
