#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
map<int, int> func(vector<int> v) {
  set<int> t(v.begin(), v.end());
  int i = 1;
  map<int, int> m;
  for (int j : t) m[j] = i++;
  return m;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(n, vector<int>(m));
  for (auto &i : a)
    for (auto &j : i) cin >> j;
  vector<vector<int>> b(m, vector<int>(n));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) b[j][i] = a[i][j];
  vector<map<int, int>> row, col;
  row.reserve(n);
  col.reserve(m);
  for (auto &i : a) {
    row.push_back(func(i));
  }
  for (auto &i : b) {
    col.push_back(func(i));
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int x = a[i][j];
      int curr = max(row[i][x], col[j][x]);
      int ans = max(row[i].size() + (curr - row[i][x]),
                    col[j].size() + (curr - col[j][x]));
      cout << ans << " ";
    }
    cout << '\n';
  }
  exit(0);
}
