#include <bits/stdc++.h>
using namespace std;
set<int> ss[1005], st[1005];
map<int, int> s_s[1005], s_t[1005];
int a[1005][1005];
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      ss[i].insert(a[i][j]);
      st[j].insert(a[i][j]);
    }
  for (int i = 0; i < n; i++) {
    int cur = 0;
    for (int j : ss[i]) {
      s_s[i][j] = cur;
      cur++;
    }
  }
  for (int i = 0; i < m; i++) {
    int cur = 0;
    for (int j : st[i]) {
      s_t[i][j] = cur;
      cur++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int x = s_s[i][a[i][j]];
      int y = s_t[j][a[i][j]];
      if (x > y)
        cout << max((int)ss[i].size(), (int)st[j].size() + x - y) << " ";
      else
        cout << max((int)ss[i].size() + y - x, (int)st[j].size()) << " ";
    }
    cout << endl;
  }
}
