#include <bits/stdc++.h>
using namespace std;
int readInt() {
  int x;
  if (scanf(" %d", &x) != EOF) return x;
  return -1;
}
long long int readLint() {
  long long int x;
  if (cin >> x) return x;
  return -1;
}
string readString() {
  string s;
  if (cin >> s) return s;
  return "";
}
struct SingleCase {
  int m, n;
  vector<vector<int> > v;
  vector<vector<int> > rowRank, colRank;
  vector<int> rowSize, colSize;
  bool solveCase() {
    m = readInt();
    if (m == -1) return false;
    n = readInt();
    v = vector<vector<int> >(m, vector<int>(n, 0));
    for (int i = 0; i < m; ++i)
      for (int j = 0; j < n; ++j) v[i][j] = readInt();
    rowRank = vector<vector<int> >(m, vector<int>(n, -1));
    rowSize = vector<int>(m, -1);
    for (int i = 0; i < m; ++i) {
      map<int, int> M;
      for (int j = 0; j < n; ++j) M[v[i][j]] = 0;
      int k = 1;
      for (auto& p : M) {
        p.second = k++;
      }
      for (int j = 0; j < n; ++j) rowRank[i][j] = M[v[i][j]];
      rowSize[i] = k - 1;
    }
    colRank = vector<vector<int> >(m, vector<int>(n, -1));
    colSize = vector<int>(n, -1);
    for (int j = 0; j < n; ++j) {
      map<int, int> M;
      for (int i = 0; i < m; ++i) M[v[i][j]] = 0;
      int k = 1;
      for (auto& p : M) {
        p.second = k++;
      }
      for (int i = 0; i < m; ++i) colRank[i][j] = M[v[i][j]];
      colSize[j] = k - 1;
    }
    for (int i = 0; i < m; ++i) {
      for (int j = 0; j < n; ++j) {
        if (j > 0) printf(" ");
        int a = max(rowRank[i][j], colRank[i][j]);
        int c1 = a + (rowSize[i] - rowRank[i][j]);
        int c2 = a + (colSize[j] - colRank[i][j]);
        int ret = max(c1, c2);
        if (i == 0 && j == 0) {
        }
        printf("%d", ret);
      }
      printf("\n");
    }
    return true;
  }
};
int main() {
  while (SingleCase().solveCase()) {
  }
}
