#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
inline int GA(long long n, vector<long long>& vec) {
  for (int i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    vec.push_back(x);
  }
  return 0;
}
inline int GAEG(long long m, vector<long long> vec[]) {
  for (int i = 0; i < m; ++i) {
    long long x, y;
    cin >> x >> y;
    x--, y--;
    vec[x].push_back(y);
    vec[y].push_back(x);
  }
  return 0;
}
bool isvalid(long long xx, long long yy, long long n, long long m) {
  return (xx >= 0 && xx < n && yy >= 0 && yy < m);
}
long long pw(long long x, long long y) {
  if (y == 0) return 1;
  long long o = y / 2;
  long long f = pw(x, o);
  if (y % 2) {
    return (((f * f)) * x);
  } else
    return (f * f);
}
long long arr[1001][1001];
vector<long long> sto[1001];
vector<long long> stt[1001];
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> arr[i][j];
      sto[i].push_back(arr[i][j]);
      stt[j].push_back(arr[i][j]);
    }
  }
  for (int i = 0; i < n; ++i) sort((sto[i]).begin(), (sto[i]).end());
  for (int i = 0; i < m; ++i) sort((stt[i]).begin(), (stt[i]).end());
  for (int i = 0; i < n; ++i) {
    long long p = unique(sto[i].begin(), sto[i].end()) - sto[i].begin();
    sto[i].resize(p);
  }
  for (int i = 0; i < m; ++i) {
    long long p = unique(stt[i].begin(), stt[i].end()) - stt[i].begin();
    stt[i].resize(p);
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      long long x =
          lower_bound(sto[i].begin(), sto[i].end(), arr[i][j]) - sto[i].begin();
      long long y =
          lower_bound(stt[j].begin(), stt[j].end(), arr[i][j]) - stt[j].begin();
      if (sto[i][x] > arr[i][j]) x--;
      if (stt[j][y] > arr[i][j]) y--;
      arr[i][j] =
          max(sto[i].size() - x - 1, stt[j].size() - y - 1) + max(x + 1, y + 1);
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) cout << arr[i][j] << " ";
    cout << endl;
  }
  return 0;
}
