#include <bits/stdc++.h>
using namespace std;
int n, m;
int arr[1001][1001];
vector<int> east[1001];
vector<int> south[1001];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &arr[i][j]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      east[i].push_back(arr[i][j]);
    }
    sort(east[i].begin(), east[i].end());
    east[i].erase(unique(east[i].begin(), east[i].end()), east[i].end());
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      south[i].push_back(arr[j][i]);
    }
    sort(south[i].begin(), south[i].end());
    south[i].erase(unique(south[i].begin(), south[i].end()), south[i].end());
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int eastIndex = lower_bound(east[i].begin(), east[i].end(), arr[i][j]) -
                      east[i].begin() + 1;
      int southIndex =
          lower_bound(south[j].begin(), south[j].end(), arr[i][j]) -
          south[j].begin() + 1;
      int actualIndex = max(eastIndex, southIndex);
      int x = max(east[i].size() + (actualIndex - eastIndex),
                  south[j].size() + (actualIndex - southIndex));
      printf("%d ", x);
    }
    printf("\n");
  }
}
