#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using str = string;
using srt = short;
const int INF = (int)1e9 + 7;
const int MOD = 998244353;
const ll inf = (ll)2e18;
const ll mod = (int)1e9 + 7;
const int N = 100000005;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> arr(n, vector<int>(m));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> arr[i][j];
    }
  }
  vector<vector<int>> line(n), bar(m);
  for (int i = 0; i < n; ++i) {
    set<int> now;
    for (int j = 0; j < m; ++j) {
      now.insert(arr[i][j]);
    }
    line[i].reserve(now.size());
    for (auto &it : now) {
      line[i].push_back(it);
    }
  }
  for (int i = 0; i < m; ++i) {
    set<int> now;
    for (int j = 0; j < n; ++j) {
      now.insert(arr[j][i]);
    }
    bar[i].reserve(now.size());
    for (auto &it : now) {
      bar[i].push_back(it);
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int biggerLine =
          line[i].end() - upper_bound(begin(line[i]), end(line[i]), arr[i][j]);
      int smallerLine = lower_bound(begin(line[i]), end(line[i]), arr[i][j]) -
                        line[i].begin();
      int biggerBar =
          bar[j].end() - upper_bound(begin(bar[j]), end(bar[j]), arr[i][j]);
      int smallerBar =
          lower_bound(begin(bar[j]), end(bar[j]), arr[i][j]) - bar[j].begin();
      cout << max(smallerBar, smallerLine) + 1 + max(biggerBar, biggerLine)
           << ' ';
    }
    cout << endl;
  }
}
