#include <bits/stdc++.h>
using namespace std;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1};
const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9 + 7;
const int maxn = 1002;
const int LOGN = 20;
vector<int> row[maxn], col[maxn];
int a[maxn][maxn];
int v[maxn][maxn];
int vv[maxn][maxn];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= (n); i++) {
    for (int j = 1; j <= (m); j++) {
      cin >> a[i][j];
      row[i].push_back(a[i][j]);
      col[j].push_back(a[i][j]);
    }
  }
  for (int i = 1; i <= (n); i++) {
    sort(row[i].begin(), row[i].end());
    row[i].erase(unique(row[i].begin(), row[i].end()), row[i].end());
    for (int j = 1; j <= (m); j++) {
      v[i][j] =
          lower_bound(row[i].begin(), row[i].end(), a[i][j]) - row[i].begin();
    }
  }
  for (int j = 1; j <= (m); j++) {
    sort(col[j].begin(), col[j].end());
    col[j].erase(unique(col[j].begin(), col[j].end()), col[j].end());
    for (int i = 1; i <= (n); i++) {
      vv[i][j] =
          lower_bound(col[j].begin(), col[j].end(), a[i][j]) - col[j].begin();
    }
  }
  for (int i = 1; i <= (n); i++) {
    for (int j = 1; j <= (m); j++) {
      int v1 = row[i].size();
      if (vv[i][j] > v[i][j]) v1 += abs(vv[i][j] - v[i][j]);
      int v2 = col[j].size();
      if (v[i][j] > vv[i][j]) v2 += abs(vv[i][j] - v[i][j]);
      cout << max(v1, v2) << " ";
    }
    cout << "\n";
  }
  return 0;
}
