#include <bits/stdc++.h>
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1000 * 1000 * 1000;
using namespace std;
const int MAX = 1005;
int idx[2][MAX][MAX];
int a[MAX][MAX];
int sz[2][MAX];
int n, m;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  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<int> v;
    for (int j = 0; j < m; j++) v.push_back(a[i][j]);
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    sz[0][i] = ((int)(v).size());
    for (int j = 0; j < m; j++) {
      idx[0][i][j] = lower_bound(v.begin(), v.end(), a[i][j]) - v.begin();
    }
  }
  for (int i = 0; i < m; i++) {
    vector<int> v;
    for (int j = 0; j < n; j++) v.push_back(a[j][i]);
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    sz[1][i] = ((int)(v).size());
    for (int j = 0; j < n; j++) {
      idx[1][j][i] = lower_bound(v.begin(), v.end(), a[j][i]) - v.begin();
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int idxH = idx[0][i][j] + 1, idxW = idx[1][i][j] + 1, szH = sz[0][i],
          szW = sz[1][j];
      cout << max(idxW, idxH) + max(szW - idxW, szH - idxH) << " ";
    }
    cout << endl;
  }
}
