#include <bits/stdc++.h>
using namespace std;
vector<int> l[1005], r[1005];
int arr[1005][1005];
int ans[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", &arr[i][j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) l[i].push_back(arr[i][j]);
    sort(l[i].begin(), l[i].end());
    l[i].erase(unique(l[i].begin(), l[i].end()), l[i].end());
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) r[i].push_back(arr[j][i]);
    sort(r[i].begin(), r[i].end());
    r[i].erase(unique(r[i].begin(), r[i].end()), r[i].end());
  }
  int ll, rl, lz, rz;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      ll = lower_bound(l[i].begin(), l[i].end(), arr[i][j]) - l[i].begin() + 1;
      rl = lower_bound(r[j].begin(), r[j].end(), arr[i][j]) - r[j].begin() + 1;
      lz = l[i].size();
      rz = r[j].size();
      ans[i][j] = max(ll, rl) + max(lz - ll, rz - rl);
    }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) cout << ans[i][j] << ' ';
    cout << endl;
  }
}
