#include <bits/stdc++.h>
using namespace std;
vector<vector<short>> H;
vector<vector<short>> V;
vector<int> L_H;
vector<int> L_V;
long tab[1000][1000];
int n, m;
int main() {
  cin >> n;
  cin >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> tab[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    vector<long> v;
    vector<short> v2;
    for (int j = 0; j < m; j++) {
      v.push_back(tab[i][j]);
    }
    sort(v.begin(), v.end());
    vector<long>::iterator it;
    it = std::unique(v.begin(), v.end());
    v.resize(distance(v.begin(), it));
    for (int j = 0; j < m; j++) {
      int a = lower_bound(v.begin(), v.end(), tab[i][j]) - v.begin() + 1;
      v2.push_back(a);
    }
    H.push_back(v2);
    L_H.push_back(v.size());
  }
  for (int j = 0; j < m; j++) {
    vector<long> v;
    vector<short> v2;
    for (int i = 0; i < n; i++) {
      v.push_back(tab[i][j]);
    }
    sort(v.begin(), v.end());
    vector<long>::iterator it;
    it = std::unique(v.begin(), v.end());
    v.resize(distance(v.begin(), it));
    for (int i = 0; i < n; i++) {
      int a = lower_bound(v.begin(), v.end(), tab[i][j]) - v.begin() + 1;
      v2.push_back(a);
    }
    V.push_back(v2);
    L_V.push_back(v.size());
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int rv = V[j][i];
      int rh = H[i][j];
      int Lrow = rh - 1;
      int Grow = L_H[i] - rh;
      int Lcol = rv - 1;
      int Gcol = L_V[j] - rv;
      int t = max(Lrow, Lcol) + 1 + max(Grow, Gcol);
      cout << t << " ";
    }
    cout << endl;
  }
  return 0;
}
