#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, N = 1e3 + 5;
inline int read() {
  int sum = 0, f = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') f = -f;
    c = getchar();
  }
  while (c >= '0' && c <= '9') sum = sum * 10 + c - 48, c = getchar();
  return sum * f;
}
int n, m, a[N][N];
vector<int> row[N], col[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      row[i].push_back(a[i][j]);
      col[j].push_back(a[i][j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    sort(row[i].begin(), row[i].end());
    row[i].erase(unique(row[i].begin(), row[i].end()), row[i].end());
  }
  for (int i = 1; i <= m; i++) {
    sort(col[i].begin(), col[i].end());
    col[i].erase(unique(col[i].begin(), col[i].end()), col[i].end());
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int l1 =
          lower_bound(row[i].begin(), row[i].end(), a[i][j]) - row[i].begin();
      int g1 =
          row[i].end() - upper_bound(row[i].begin(), row[i].end(), a[i][j]);
      int l2 =
          lower_bound(col[j].begin(), col[j].end(), a[i][j]) - col[j].begin();
      int g2 =
          col[j].end() - upper_bound(col[j].begin(), col[j].end(), a[i][j]);
      char c = j == m ? '\n' : ' ';
      cout << max(l1, l2) + max(g1, g2) + 1 << c;
    }
  }
  return 0;
}
