#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > num, num1, temp, temp1;
int ans[1005][1005], n1[1005], n2[1005];
int main() {
  int n, m, x, y, x1, y1, a, b;
  vector<int> t;
  scanf("%d%d", &n, &m);
  for (int(q) = 0; (q) < (n); (q)++) {
    for (int(qq) = 0; (qq) < (m); (qq)++) {
      scanf("%d", &x);
      t.push_back(x);
    }
    num.push_back(t);
    t.clear();
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      t.push_back(num[j][i]);
    }
    num1.push_back(t);
    t.clear();
  }
  temp = num;
  temp1 = num1;
  for (int i = 0; i < n; i++) {
    sort(temp[i].begin(), temp[i].end());
    n1[i] = unique(temp[i].begin(), temp[i].end()) - temp[i].begin();
    temp[i].resize(n1[i]);
  }
  for (int j = 0; j < m; j++) {
    sort(temp1[j].begin(), temp1[j].end());
    n2[j] = unique(temp1[j].begin(), temp1[j].end()) - temp1[j].begin();
    temp1[j].resize(n2[j]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      x = lower_bound(temp[i].begin(), temp[i].end(), num[i][j]) -
          temp[i].begin();
      y = lower_bound(temp1[j].begin(), temp1[j].end(), num[i][j]) -
          temp1[j].begin();
      ans[i][j] = max(x, y) + max(n1[i] - x - 1, n2[j] - y - 1) + 1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cout << ans[i][j];
      if (j != m - 1)
        cout << ' ';
      else
        cout << endl;
    }
  }
}
