#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;
  vector<vector<int>> mat(n, vector<int>(m));
  vector<vector<int>> temp1(n, vector<int>(m));
  vector<vector<int>> temp2(m, vector<int>(n));
  vector<vector<int>> mat1(n, vector<int>(m));
  vector<vector<int>> mat2(m, vector<int>(n));
  vector<vector<int>> ans(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> mat[i][j];
      temp1[i][j] = mat[i][j];
      temp2[j][i] = mat[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    sort(temp1[i].begin(), temp1[i].end());
    temp1[i].erase(unique(temp1[i].begin(), temp1[i].end()), temp1[i].end());
    int mg = 0;
    for (int j = 0; j < m; j++) {
      mat1[i][j] = lower_bound(temp1[i].begin(), temp1[i].end(), mat[i][j]) -
                   temp1[i].begin();
      mg = max(mg, mat1[i][j]);
    }
    temp1[i].push_back(mg);
  }
  for (int i = 0; i < m; i++) {
    sort(temp2[i].begin(), temp2[i].end());
    temp2[i].erase(unique(temp2[i].begin(), temp2[i].end()), temp2[i].end());
    int mg = 0;
    for (int j = 0; j < n; j++) {
      mat2[i][j] = lower_bound(temp2[i].begin(), temp2[i].end(), mat[j][i]) -
                   temp2[i].begin();
      mg = max(mg, mat2[i][j]);
    }
    temp2[i].push_back(mg);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (mat2[j][i] == mat1[i][j]) {
        ans[i][j] =
            max(temp1[i][temp1[i].size() - 1], temp2[j][temp2[j].size() - 1]);
      } else if (mat2[j][i] > mat1[i][j]) {
        ans[i][j] = max(mat2[j][i] - mat1[i][j] + temp1[i][temp1[i].size() - 1],
                        temp2[j][temp2[j].size() - 1]);
      } else {
        ans[i][j] =
            max(-mat2[j][i] + mat1[i][j] + temp2[j][temp2[j].size() - 1],
                temp1[i][temp1[i].size() - 1]);
      }
      cout << ans[i][j] + 1 << " ";
    }
    cout << "\n";
  }
}
