#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 9;
const long long int MOD = 1e9 + 696969;
const long long INF = 1e18 + 3;
const int maxn = 1010;
int tab[maxn][maxn];
int posx[maxn][maxn], largex[maxn][maxn], posy[maxn][maxn], largey[maxn][maxn];
int n, m;
pair<int, int> help[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = (1); i <= (n); ++i)
    for (int j = (1); j <= (m); ++j) cin >> tab[i][j];
  for (int row = (1); row <= (n); ++row) {
    for (int i = (1); i <= (m); ++i) help[i] = make_pair(tab[row][i], i);
    sort(help + 1, help + m + 1);
    help[m + 1].first = -1;
    int score = 0;
    int wsk = m;
    for (int i = m; i > 0; --i) {
      while (help[wsk].first > help[i].first) {
        if (help[wsk].first != help[wsk + 1].first) ++score;
        --wsk;
      }
      largex[row][help[i].second] = score;
    }
    score = 0;
    help[0].first = -1;
    for (int i = 1; i <= m; ++i) {
      if (help[i].first > help[i - 1].first) {
        ++score;
      }
      posx[row][help[i].second] = score;
    }
  }
  for (int col = (1); col <= (m); ++col) {
    for (int i = (1); i <= (n); ++i) help[i] = make_pair(tab[i][col], i);
    sort(help + 1, help + n + 1);
    int score = 0;
    int wsk = n;
    help[n + 1].first = -1;
    for (int i = n; i > 0; --i) {
      while (help[wsk].first > help[i].first) {
        if (help[wsk].first != help[wsk + 1].first) ++score;
        --wsk;
      }
      largey[help[i].second][col] = score;
    }
    score = 0;
    help[0].first = -1;
    for (int i = 1; i <= n; ++i) {
      if (help[i].first > help[i - 1].first) {
        ++score;
      }
      posy[help[i].second][col] = score;
    }
  }
  for (int i = (1); i <= (n); ++i) {
    for (int j = (1); j <= (m); ++j)
      cout << max(posx[i][j], posy[i][j]) + max(largex[i][j], largey[i][j])
           << ' ';
    cout << "\n";
  }
}
