#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 5;
const long long inf = 1791791791;
const long long mod = 1e9 + 7;
int a[N][N];
int mxc[N][N], mnc[N][N];
int mxr[N][N], mnr[N][N];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  vector<int> v;
  set<int> s;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      s.insert(a[i][j]);
    }
    for (auto ss : s) {
      v.push_back(ss);
    }
    for (int j = 0; j < m; j++) {
      int p = lower_bound(v.begin(), v.end(), a[i][j]) - v.begin();
      mnr[i][j] = p;
      mxr[i][j] = (int)v.size() - p - 1;
    }
    s.clear();
    v.clear();
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      s.insert(a[i][j]);
    }
    for (auto ss : s) {
      v.push_back(ss);
    }
    for (int i = 0; i < n; i++) {
      int p = lower_bound(v.begin(), v.end(), a[i][j]) - v.begin();
      mnc[i][j] = p;
      mxc[i][j] = (int)v.size() - p - 1;
    }
    s.clear();
    v.clear();
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      printf("%d ", 1 + max(mxc[i][j], mxr[i][j]) + max(mnc[i][j], mnr[i][j]));
    }
    printf("\n");
  }
  return 0;
}
