#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int n, m;
int a[maxn][maxn];
set<int> s1[maxn], s2[maxn];
map<int, int> mp1[maxn], mp2[maxn];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
      s1[i].insert(a[i][j]);
      s2[j].insert(a[i][j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    int od = 1;
    for (int x : s1[i]) mp1[i][x] = od++;
  }
  for (int i = 1; i <= m; i++) {
    int od = 1;
    for (int x : s2[i]) mp2[i][x] = od++;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int xx = mp1[i][a[i][j]];
      int yy = mp2[j][a[i][j]];
      printf("%d ", max(xx, yy) + max(s1[i].size() - xx, s2[j].size() - yy));
    }
    printf("\n");
  }
  return 0;
}
