#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 7;
vector<int> v[maxn], u[maxn];
int a[maxn][maxn];
int main() {
  int n, m;
  cin >> 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++) {
    for (int j = 1; j <= m; j++) v[i].push_back(a[i][j]);
    sort(v[i].begin(), v[i].end());
    v[i].erase(unique(v[i].begin(), v[i].end()), v[i].end());
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) u[i].push_back(a[j][i]);
    sort(u[i].begin(), u[i].end());
    u[i].erase(unique(u[i].begin(), u[i].end()), u[i].end());
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int temp1 = lower_bound(v[i].begin(), v[i].end(), a[i][j]) - v[i].begin();
      int temp2 = lower_bound(u[j].begin(), u[j].end(), a[i][j]) - u[j].begin();
      int temp3 = v[i].end() - lower_bound(v[i].begin(), v[i].end(), a[i][j]);
      int temp4 = u[j].end() - lower_bound(u[j].begin(), u[j].end(), a[i][j]);
      printf("%d", max(temp1, temp2) + max(temp3, temp4));
      if (j != m)
        printf(" ");
      else
        printf("\n");
    }
}
