#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
int matrix[maxn][maxn];
vector<int> satr[maxn];
vector<int> sotoon[maxn];
int n, m;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  set<int> s;
  for (int i = (int)1; i <= (int)n; i++) {
    for (int j = (int)1; j <= (int)m; j++) {
      cin >> matrix[i][j];
      s.insert(matrix[i][j]);
    }
    satr[i].assign((s).begin(), (s).end());
    s.clear();
  }
  for (int j = (int)1; j <= (int)m; j++) {
    for (int i = (int)1; i <= (int)n; i++) {
      s.insert(matrix[i][j]);
    }
    sotoon[j].assign((s).begin(), (s).end());
    s.clear();
  }
  for (int i = (int)1; i <= (int)n; i++) {
    for (int j = (int)1; j <= (int)m; j++) {
      int first =
          lower_bound((satr[i]).begin(), (satr[i]).end(), matrix[i][j]) -
          satr[i].begin() + 1;
      int second =
          lower_bound((sotoon[j]).begin(), (sotoon[j]).end(), matrix[i][j]) -
          sotoon[j].begin() + 1;
      int third = max(first, second);
      matrix[i][j] = max(third + satr[i].size() - first,
                         third + sotoon[j].size() - second);
    }
  }
  for (int i = (int)1; i <= (int)n; i++) {
    for (int j = (int)1; j <= (int)m; j++) {
      cout << matrix[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
