#include <bits/stdc++.h>
using namespace std;
void canhazfast() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
T extgcd(T a, T b, T &x, T &y) {
  T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
  while (b) {
    T q = a / b;
    a %= b;
    swap(a, b);
    x0 -= q * x1;
    swap(x0, x1);
    y0 -= q * y1;
    swap(y0, y1);
  }
  x = x0;
  y = y0;
  return a;
}
int ctz(unsigned x) { return __builtin_ctz(x); }
int ctzll(unsigned long long x) { return __builtin_ctzll(x); }
int clz(unsigned x) { return __builtin_clz(x); }
int clzll(unsigned long long x) { return __builtin_clzll(x); }
int popcnt(unsigned x) { return __builtin_popcount(x); }
int popcntll(unsigned long long x) { return __builtin_popcountll(x); }
int bsr(unsigned x) { return 31 ^ clz(x); }
int bsrll(unsigned long long x) { return 63 ^ clzll(x); }
int a[1024][1024];
int main() {
  canhazfast();
  int n, m;
  vector<vector<int> > row, col;
  cin >> n >> m;
  row.resize(n, vector<int>(m));
  col.resize(m, vector<int>(n));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
      row[i][j] = a[i][j];
      col[j][i] = a[i][j];
    }
    sort((row[i]).begin(), (row[i]).end());
    row[i].erase(unique((row[i]).begin(), (row[i]).end()), row[i].end());
  }
  for (int j = 0; 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 = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int rl = lower_bound((row[i]).begin(), (row[i]).end(), a[i][j]) -
               row[i].begin();
      int rh =
          row[i].end() - upper_bound((row[i]).begin(), (row[i]).end(), a[i][j]);
      int cl = lower_bound((col[j]).begin(), (col[j]).end(), a[i][j]) -
               col[j].begin();
      int ch =
          col[j].end() - upper_bound((col[j]).begin(), (col[j]).end(), a[i][j]);
      int ans = max(rl, cl) + max(rh, ch) + 1;
      cout << ans << ' ';
    }
    cout << '\n';
  }
  return 0;
}
