#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 10;
int maze[MAXN][MAXN];
int mi[MAXN][MAXN];
int ma[MAXN][MAXN];
int a[MAXN];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) scanf("%d", &maze[i][j]);
  }
  for (int i = 1; i <= n; i++) {
    memcpy(a, maze[i], sizeof(a));
    sort(a + 1, a + 1 + m);
    int k = unique(a + 1, a + 1 + m) - (a + 1);
    unordered_map<int, int> mp;
    for (int j = 1; j <= k; j++) mp[a[j]] = j;
    for (int j = 1; j <= m; j++) {
      mi[i][j] = mp[maze[i][j]];
      ma[i][j] = k - mp[maze[i][j]];
    }
  }
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++) a[i] = maze[i][j];
    sort(a + 1, a + 1 + n);
    int k = unique(a + 1, a + 1 + n) - a - 1;
    unordered_map<int, int> mp;
    for (int j = 1; j <= k; j++) mp[a[j]] = j;
    for (int i = 1; i <= n; i++) {
      mi[i][j] = max(mi[i][j], mp[maze[i][j]]);
      ma[i][j] = max(ma[i][j], k - mp[maze[i][j]]);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      printf("%d%c", mi[i][j] + ma[i][j], j == m ? '\n' : ' ');
  }
  return 0;
}
