#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(n, vector<int>(m)), n_s(1001, vector<int>(1001)),
      n_c(1001, vector<int>(1001));
  vector<int> m_s(1001), m_c(1001);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  for (int i = 0; i < n; i++) {
    vector<pair<int, int>> num;
    for (int j = 0; j < m; j++) num.push_back(make_pair(a[i][j], j));
    sort(num.begin(), num.end());
    int h = 0;
    for (int k = 0; k < num.size(); k++) {
      if (k && num[k].first != num[k - 1].first) h++;
      n_s[i][num[k].second] = h;
    }
    m_s[i] = h;
  }
  for (int i = 0; i < m; i++) {
    vector<pair<int, int>> num;
    for (int j = 0; j < n; j++) num.push_back(make_pair(a[j][i], j));
    sort(num.begin(), num.end());
    int h = 0;
    for (int k = 0; k < num.size(); k++) {
      if (k && num[k].first != num[k - 1].first) h++;
      n_c[i][num[k].second] = h;
    }
    m_c[i] = h;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int l_s = n_s[i][j];
      int l_c = n_c[j][i];
      int g_s = m_s[i] - l_s;
      int g_c = m_c[j] - l_c;
      cout << max(l_s, l_c) + 1 + max(g_s, g_c) << ' ';
    }
    cout << endl;
  }
  return 0;
}
