#include <bits/stdc++.h>
using namespace std;
const int SI = 5e5 + 100;
const long long mod = 1e9 + 7;
int mp[1005][1005];
int n, m;
vector<int> han[1005], lie[1005];
int ans[1005][1005];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf("%d", &mp[i][j]);
      han[i].push_back(mp[i][j]);
      lie[j].push_back(mp[i][j]);
    }
  for (int i = 1; i <= n; i++) {
    sort(han[i].begin(), han[i].end());
    han[i].erase(unique(han[i].begin(), han[i].end()), han[i].end());
  }
  for (int i = 1; i <= m; i++) {
    sort(lie[i].begin(), lie[i].end());
    lie[i].erase(unique(lie[i].begin(), lie[i].end()), lie[i].end());
  }
  int ad = lower_bound(han[1].begin(), han[1].end(), 1) - han[1].begin();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int be1 = lower_bound(han[i].begin(), han[i].end(), mp[i][j]) -
                han[i].begin() + 1;
      int ed1 = (int)han[i].size() - be1;
      int be2 = lower_bound(lie[j].begin(), lie[j].end(), mp[i][j]) -
                lie[j].begin() + 1;
      int ed2 = (int)lie[j].size() - be2;
      ans[i][j] = max(be1, be2) + max(ed1, ed2);
    }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cout << ans[i][j] << ' ';
    }
    cout << endl;
  }
  return 0;
}
