#include <bits/stdc++.h>
using namespace std;
const int sz = 1001;
int arr[sz][sz];
int n, m;
vector<vector<int> > colVec(sz), rowVec(sz);
void fnc() {
  set<int> st;
  for (int i = 0; i < m; i++) {
    st.clear();
    for (int j = 0; j < n; j++) st.insert(arr[j][i]);
    for (set<int>::iterator it = st.begin(); it != st.end(); it++)
      colVec[i].push_back(*it);
  }
  for (int i = 0; i < n; i++) {
    st.clear();
    for (int j = 0; j < m; j++) st.insert(arr[i][j]);
    for (set<int>::iterator it = st.begin(); it != st.end(); it++)
      rowVec[i].push_back(*it);
  }
}
int binSrc(int i, int j, bool isCol) {
  int key = arr[i][j];
  vector<int> vec;
  if (isCol)
    vec = colVec[j];
  else
    vec = rowVec[i];
  int lo = 0, hi = vec.size() - 1, mid;
  while (lo <= hi) {
    mid = (lo + hi) / 2;
    if (vec[mid] == key)
      return mid;
    else if (vec[mid] > key)
      hi = mid - 1;
    else
      lo = mid + 1;
  }
}
int main() {
  int row, col, ans;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &arr[i][j]);
  fnc();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      row = binSrc(i, j, false);
      col = binSrc(i, j, true);
      ans = max(rowVec[i].size() - 1, colVec[j].size() - 1);
      if (col > row) {
        ans = max(colVec[j].size() - 1, rowVec[i].size() - 1 + col - row);
      } else if (row > col) {
        ans = max(rowVec[i].size() - 1, colVec[j].size() - 1 + row - col);
      }
      arr[i][j] = ans + 1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) printf("%d ", arr[i][j]);
    printf("\n");
  }
  return 0;
}
