#include <bits/stdc++.h>
using namespace std;
int a[1002][1002];
struct node {
  int x, flag;
} b[1002];
int l[1002], r[1002], c[1002][1002], d[1002][1002];
bool cmp1(node x, node y) { return x.x < y.x; }
bool cmp2(node x, node y) { return x.flag < y.flag; }
void init() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  int n, m;
  init();
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) b[j].x = a[i][j], b[j].flag = j;
    sort(b, b + m, cmp1);
    int cnt = 1, flag;
    for (int j = 0; j < m; j++) {
      if (j == 0) {
        flag = b[j].x;
        b[j].x = cnt;
      } else {
        if (b[j].x == flag)
          b[j].x = cnt;
        else {
          flag = b[j].x;
          b[j].x = ++cnt;
        }
      }
    }
    l[i] = b[m - 1].x;
    sort(b, b + m, cmp2);
    for (int j = 0; j < m; j++) c[i][j] = b[j].x;
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) b[j].x = a[j][i], b[j].flag = j;
    sort(b, b + n, cmp1);
    int cnt = 1, flag;
    for (int j = 0; j < n; j++) {
      if (j == 0) {
        flag = b[j].x;
        b[j].x = cnt;
      } else {
        if (flag == b[j].x)
          b[j].x = cnt;
        else {
          flag = b[j].x;
          b[j].x = ++cnt;
        }
      }
    }
    r[i] = b[n - 1].x;
    sort(b, b + n, cmp2);
    for (int j = 0; j < n; j++) d[j][i] = b[j].x;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (c[i][j] == d[i][j])
        cout << max(l[i], r[j]) << " ";
      else if (c[i][j] > d[i][j])
        cout << max(c[i][j] - d[i][j] + r[j], l[i]) << " ";
      else
        cout << max(r[j], l[i] + d[i][j] - c[i][j]) << " ";
    }
    cout << endl;
  }
  return 0;
}
