#include <bits/stdc++.h>
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
vector<vector<int>> hor, ver;
vector<int> horr, verr;
struct num {
  int val, hor, ver;
};
class Compare {
 public:
  bool operator()(const num &a, const num &b) const { return a.val < b.val; }
};
void doItHor(vector<num> nums) {
  sort(nums.begin(), nums.end(), Compare());
  int vr = nums[0].ver;
  int num = 1;
  for (int i = 0; i < nums.size(); i++) {
    if (i != 0 && nums[i].val != nums[i - 1].val) num++;
    int hr = nums[i].hor;
    hor[vr][hr] = num;
  }
  horr[vr] = num;
}
void doItVer(vector<num> nums) {
  sort(nums.begin(), nums.end(), Compare());
  int hr = nums[0].hor;
  int num = 1;
  for (int i = 0; i < nums.size(); i++) {
    if (i != 0 && nums[i].val != nums[i - 1].val) num++;
    int vr = nums[i].ver;
    ver[vr][hr] = num;
  }
  verr[hr] = num;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<num>> nums(n, vector<num>(m));
  hor.resize(n, vector<int>(m));
  ver.resize(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int a;
      cin >> a;
      nums[i][j] = {a, j, i};
    }
  }
  horr.resize(n);
  verr.resize(m);
  for (int i = 0; i < n; i++) {
    doItHor(nums[i]);
  }
  for (int i = 0; i < m; i++) {
    vector<num> cur(n);
    for (int j = 0; j < n; j++) cur[j] = nums[j][i];
    doItVer(cur);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int a = hor[i][j];
      int b = ver[i][j];
      int cur = max(max(a, b) - a + horr[i], max(a, b) - b + verr[j]);
      cout << cur << ' ';
    }
    cout << '\n';
  }
}
