#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
long long n, m;
vector<vector<long long> > v;
long long arr[1005][1005];
long long arr2[1005][1005];
vector<long long> row, col;
set<long long> s;
map<long long, long long> mp;
void work2() {
  for (int i = 0; i < m; i++) {
    s.clear();
    int cnt = 0;
    mp.clear();
    for (int j = 0; j < n; j++) {
      long long t = v[j][i];
      s.insert(t);
    }
    for (auto x : s) {
      mp[x] = cnt++;
    }
    for (int j = 0; j < n; j++) {
      arr2[j][i] = mp[v[j][i]];
    }
    col[i] = s.size();
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cout << max(row[i] - arr[i][j] + arr2[i][j],
                  max(row[i], max(col[j] - arr2[i][j] + arr[i][j], col[j])))
           << ' ';
    }
    cout << endl;
    ;
  }
  exit(0);
}
void work() {
  for (int i = 0; i < n; i++) {
    s.clear();
    for (int j = 0; j < m; j++) {
      s.insert(v[i][j]);
    }
    int cnt = 0;
    mp.clear();
    for (auto x : s) {
      mp[x] = cnt++;
    }
    for (int j = 0; j < m; j++) {
      arr[i][j] = mp[v[i][j]];
    }
    row[i] = s.size();
  }
  work2();
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n >> m;
  v.resize(n);
  row.resize(n);
  col.resize(m);
  for (int i = 0; i < n; i++) {
    v[i].resize(m);
    for (int j = 0; j < m; j++) cin >> v[i][j];
  }
  work();
  return 0;
}
