#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
istream &operator>>(istream &in, pair<T1, T2> &P) {
  in >> P.first >> P.second;
  return in;
}
template <class T1, class T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &P) {
  out << "(" << P.first << ", " << P.second << ")";
  return out;
}
template <class T>
istream &operator>>(istream &in, vector<T> &arr) {
  for (auto &x : arr) in >> x;
  return in;
}
template <class T>
ostream &operator<<(ostream &out, const vector<T> &arr) {
  for (auto &x : arr) out << x << ' ';
  cout << "\n";
  return out;
}
template <class T>
istream &operator>>(istream &in, deque<T> &arr) {
  for (auto &x : arr) in >> x;
  return in;
}
template <class T>
ostream &operator<<(ostream &out, const deque<T> &arr) {
  for (auto &x : arr) out << x << ' ';
  cout << "\n";
  return out;
}
int a[1001][1001];
vector<int> h[1001];
int n, m;
int posL[1001][1001];
int posC[1001][1001];
int szL[1001];
int szC[1001];
int solve(int x, int y) {
  return (max(posL[x][y], posC[x][y]) +
          max(szL[x] - posL[x][y], szC[y] - posC[x][y]));
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    h[i].resize(m);
    cin >> h[i];
  }
  for (int i = 0; i < n; i++) {
    set<int> rx;
    for (auto w : h[i]) rx.insert(w);
    map<int, int> rr;
    int cc = 0;
    for (auto w : rx) {
      rr[w] = ++cc;
    }
    szL[i] = rx.size();
    for (int j = 0; j < m; j++) {
      posL[i][j] = rr[h[i][j]];
    }
  }
  for (int j = 0; j < m; j++) {
    set<int> rx;
    for (int i = 0; i < n; i++) {
      rx.insert(h[i][j]);
    }
    map<int, int> rr;
    int cc = 0;
    szC[j] = rx.size();
    for (auto w : rx) rr[w] = ++cc;
    for (int i = 0; i < n; i++) posC[i][j] = rr[h[i][j]];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cout << solve(i, j) << " ";
    }
    cout << endl;
  }
}
