#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  long long a[n][m];
  vector<long long> east[n], south[m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      long long x;
      cin >> x;
      a[i][j] = x;
      east[i].push_back(x);
      south[j].push_back(x);
    }
  }
  for (int i = 0; i < n; i++) {
    sort(east[i].begin(), east[i].end());
    east[i].erase(unique(east[i].begin(), east[i].end()), east[i].end());
  }
  for (int j = 0; j < m; j++) {
    sort(south[j].begin(), south[j].end());
    south[j].erase(unique(south[j].begin(), south[j].end()), south[j].end());
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      long long x = a[i][j];
      long long r = find(east[i].begin(), east[i].end(), x) - east[i].begin();
      long long R = east[i].size();
      long long c =
          find(south[j].begin(), south[j].end(), x) - south[j].begin();
      long long C = south[j].size();
      long long ans = max(r, c) + max(R - r, C - c);
      cout << ans << " ";
    }
    cout << "\n";
  }
  return 0;
}
