#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 5;
const int inf = (int)1e9 + 7;
int n, m;
int a[1001][1001];
int r[1001][1001], c[1001][1001];
int mxr[1001], mxc[1001];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      scanf(" %d", a[i] + j);
    }
  }
  for (int i = 1; i <= n; ++i) {
    vector<pair<int, int> > all;
    for (int j = 1; j <= m; ++j) {
      all.push_back(make_pair(a[i][j], j));
    }
    sort(all.begin(), all.end());
    int prev = 0, now = 0;
    for (auto j : all) {
      if (j.first != prev) ++now;
      r[i][j.second] = now;
      prev = j.first;
    }
    mxr[i] = now;
  }
  for (int j = 1; j <= m; ++j) {
    vector<pair<int, int> > all;
    for (int i = 1; i <= n; ++i) {
      all.push_back(make_pair(a[i][j], i));
    }
    sort(all.begin(), all.end());
    int prev = 0, now = 0;
    for (auto i : all) {
      if (i.first != prev) ++now;
      c[i.second][j] = now;
      prev = i.first;
    }
    mxc[j] = now;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      int cur = max(r[i][j], c[i][j]);
      printf("%d ", cur + max(mxr[i] - r[i][j], mxc[j] - c[i][j]));
    }
    printf("\n");
  }
  return 0;
}
