#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int t = 1;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    vector<vector<long long int>> v(n);
    vector<set<long long int>> cs(m);
    vector<set<long long int>> rs(n);
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 0; j < m; j++) {
        long long int a;
        cin >> a;
        v[i].push_back(a);
        cs[j].insert(a);
        rs[i].insert(a);
      }
    }
    vector<vector<long long int>> r(n);
    vector<vector<long long int>> c(m);
    set<long long int>::iterator it;
    for (long long int i = 0; i < n; i++) {
      for (it = rs[i].begin(); it != rs[i].end(); it++) r[i].push_back(*it);
    }
    for (long long int i = 0; i < m; i++) {
      for (it = cs[i].begin(); it != cs[i].end(); it++) c[i].push_back(*it);
    }
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 0; j < m; j++) {
        long long int d = v[i][j];
        long long int p1 =
            lower_bound(r[i].begin(), r[i].end(), d) - r[i].begin();
        long long int p2 =
            lower_bound(c[j].begin(), c[j].end(), d) - c[j].begin();
        long long int a = p1 + 1;
        long long int b = p2 + 1;
        long long int o = max(a, b);
        p1 = upper_bound(r[i].begin(), r[i].end(), d) - r[i].begin();
        p2 = upper_bound(c[j].begin(), c[j].end(), d) - c[j].begin();
        b = (c[j].size() - p2);
        a = (r[i].size() - p1);
        cout << max(o + a, o + b) << " ";
      }
      cout << endl;
    }
  }
}
