#include <bits/stdc++.h>
using namespace std;
const long long P = 998244353;
const int INF = 0x3fffffff;
const int N = 1005;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
set<int> s1[N], s2[N];
int a[N][N], b[N], nc[N], nr[N], ranki[N][N], rankj[N][N];
int m, n;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (1); i <= (n); ++i)
    for (int j = (1); j <= (m); ++j) scanf("%d", a[i] + j);
  for (int i = (1); i <= (n); ++i) {
    memcpy(b, a[i], sizeof b);
    sort(b + 1, b + m + 1);
    int n1 = unique(b + 1, b + m + 1) - b - 1;
    for (int j = (1); j <= (m); ++j)
      ranki[i][j] = lower_bound(b + 1, b + n1 + 1, a[i][j]) - b;
    nr[i] = n1;
  }
  for (int j = (1); j <= (m); ++j) {
    for (int i = (1); i <= (n); ++i) b[i] = a[i][j];
    sort(b + 1, b + n + 1);
    int n1 = unique(b + 1, b + n + 1) - b - 1;
    for (int i = (1); i <= (n); ++i)
      rankj[i][j] = lower_bound(b + 1, b + n1 + 1, a[i][j]) - b;
    nc[j] = n1;
  }
  for (int i = (1); i <= (n); ++i)
    for (int j = (1); j <= (m); ++j) {
      int ans = max(ranki[i][j], rankj[i][j]);
      ans += max(nr[i] - ranki[i][j], nc[j] - rankj[i][j]);
      printf("%d%c", ans, j == m ? '\n' : ' ');
    }
  return 0;
}
