#include <bits/stdc++.h>
using namespace std;
int n, a[1010][1010], m;
int ma1[1010][1010], mi1[1010][1010];
int ma2[1010][1010], mi2[1010][1010];
vector<int> v;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) scanf("%d", &a[i][j]);
  }
  for (int i = 0; i < n; ++i) {
    v.clear();
    for (int j = 0; j < m; ++j) v.push_back(a[i][j]);
    sort(v.begin(), v.end());
    int end = unique(v.begin(), v.end()) - v.begin();
    for (int j = 0; j < m; ++j) {
      mi1[i][j] =
          (int)(lower_bound(v.begin(), v.begin() + end, a[i][j]) - v.begin());
      ma1[i][j] = end - mi1[i][j] - 1;
    }
  }
  for (int i = 0; i < m; ++i) {
    v.clear();
    for (int j = 0; j < n; ++j) v.push_back(a[j][i]);
    sort(v.begin(), v.end());
    int end = unique(v.begin(), v.end()) - v.begin();
    for (int j = 0; j < n; ++j) {
      mi2[j][i] =
          (int)(lower_bound(v.begin(), v.begin() + end, a[j][i]) - v.begin());
      ma2[j][i] = end - mi2[j][i] - 1;
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j)
      printf("%d ", 1 + max(mi1[i][j], mi2[i][j]) + max(ma1[i][j], ma2[i][j]));
    printf("\n");
  }
}
