#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[1010][1010];
map<int, int> mp;
pair<int, int> t[1010];
int r[1010][1010], c[1010][1010];
int nr[1010], nc[1010];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) t[j] = pair<int, int>(a[i][j], j);
    sort(t + 1, t + m + 1);
    for (int j = 1; j <= m; j++)
      r[i][t[j].second] =
          r[i][t[j - 1].second] + (t[j].first != t[j - 1].first);
    nr[i] = r[i][t[m].second];
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) t[j] = pair<int, int>(a[j][i], j);
    sort(t + 1, t + n + 1);
    for (int j = 1; j <= n; j++)
      c[t[j].second][i] =
          c[t[j - 1].second][i] + (t[j].first != t[j - 1].first);
    nc[i] = c[t[n].second][i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cout << max(r[i][j], c[i][j]) + max(nr[i] - r[i][j], nc[j] - c[i][j])
           << ' ';
    }
    cout << endl;
  }
  return 0;
}
