#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
template <typename T>
T gcd(T a, T b) {
  return (b ? __gcd(a, b) : a);
}
template <typename T>
T lcm(T a, T b) {
  return (a * (b / gcd(a, b)));
}
void go() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
void solution() {
  long long n, m;
  cin >> n >> m;
  long long a[n][m];
  vector<vector<long long>> d(n, vector<long long>(m, 0));
  vector<vector<long long>> l(n, vector<long long>(m, 0));
  vector<vector<long long>> mxl(n, vector<long long>(m, 0));
  vector<vector<long long>> mxd(n, vector<long long>(m, 0));
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }
  for (long long i = 0; i < n; ++i) {
    long long c = 1;
    set<long long> aa;
    map<long long, long long> ma;
    for (long long j = 0; j < m; ++j) {
      aa.insert(a[i][j]);
    }
    for (long long i1 : aa) {
      ma[i1] = c++;
    }
    for (long long j = 0; j < m; ++j) {
      mxl[i][j] = c - 1;
    }
    for (long long j = 0; j < m; ++j) {
      l[i][j] = ma[a[i][j]];
    }
  }
  for (long long i = 0; i < m; ++i) {
    long long c = 1;
    set<long long> aa;
    map<long long, long long> ma;
    for (long long j = 0; j < n; ++j) {
      aa.insert(a[j][i]);
    }
    for (long long i1 : aa) {
      ma[i1] = c++;
    }
    for (long long j = 0; j < n; ++j) {
      mxd[j][i] = c - 1;
    }
    for (long long j = 0; j < n; ++j) {
      d[j][i] = ma[a[j][i]];
    }
  }
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j < m; ++j) {
      cout << max(mxl[i][j] + max(0LL, d[i][j] - l[i][j]),
                  mxd[i][j] + max(0LL, l[i][j] - d[i][j]))
           << " ";
    }
    cout << "\n";
  }
}
signed main() {
  go();
  solution();
  return 0;
}
