#include <bits/stdc++.h>
using namespace std;
int A[1005][1005];
vector<int> r[1005], c[1006];
int ans[1005][1005];
int main() {
  int N, M, i, j, k;
  scanf("%d %d", &N, &M);
  for (i = 1; i <= N; i++)
    for (j = 1; j <= M; j++) scanf("%d", &A[i][j]);
  for (i = 1; i <= N; i++) {
    set<int> lol;
    for (j = 1; j <= M; j++) {
      lol.insert(A[i][j]);
    }
    for (set<int>::iterator it = lol.begin(); it != lol.end(); it++)
      r[i].push_back(*it);
  }
  for (j = 1; j <= M; j++) {
    set<int> lol;
    for (i = 1; i <= N; i++) lol.insert(A[i][j]);
    for (set<int>::iterator it = lol.begin(); it != lol.end(); it++)
      c[j].push_back(*it);
  }
  for (i = 1; i <= N; i++) {
    for (j = 1; j <= M; j++) {
      int a1 = -1;
      int s = 0, e = (int)r[i].size() - 1;
      while (s <= e) {
        int m = (s + e) / 2;
        if (r[i][m] <= A[i][j]) {
          a1 = m;
          s = m + 1;
        } else
          e = m - 1;
      }
      a1++;
      int a2 = -1;
      s = 0, e = (int)c[j].size() - 1;
      while (s <= e) {
        int m = (s + e) / 2;
        if (c[j][m] <= A[i][j]) {
          a2 = m;
          s = m + 1;
        } else
          e = m - 1;
      }
      a2++;
      int rem_r = (int)r[i].size() - a1;
      int rem_c = (int)c[j].size() - a2;
      int maxi = max(a1, a2);
      ans[i][j] = maxi + max(rem_c, rem_r);
    }
  }
  for (i = 1; i <= N; i++) {
    for (j = 1; j <= M; j++) {
      cout << ans[i][j] << " ";
    }
    cout << "\n";
  }
  return 0;
}
