#include <bits/stdc++.h>
using namespace std;
inline char gc() { return getchar(); }
template <class T>
int read(T &ans) {
  ans = 0;
  char ch = gc();
  T f = 1;
  while (!isdigit(ch)) {
    if (ch == EOF) return -1;
    if (ch == '-') f = -1;
    ch = gc();
  }
  while (isdigit(ch)) ans = ans * 10 + ch - '0', ch = gc();
  ans *= f;
  return 1;
}
template <class T1, class T2>
int read(T1 &a, T2 &b) {
  return read(a) != EOF && read(b) != EOF ? 2 : EOF;
}
template <class T1, class T2, class T3>
int read(T1 &a, T2 &b, T3 &c) {
  return read(a, b) != EOF && read(c) != EOF ? 3 : EOF;
}
const int Maxn = 1100;
const int inf = 0x3f3f3f3f;
int n, m, mp[Maxn][Maxn], l[Maxn][Maxn], h[Maxn][Maxn], b[Maxn], num[Maxn],
    num2[Maxn];
int main() {
  read(n, m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) read(mp[i][j]);
  for (int i = 1; i <= n; i++) {
    map<int, int> ma;
    for (int j = 1; j <= m; j++) b[j] = mp[i][j];
    sort(b + 1, b + m + 1);
    for (int j = 1; j <= m; j++)
      if (!ma[b[j]]) ma[b[j]] = ++num[i];
    for (int j = 1; j <= m; j++) h[i][j] = ma[mp[i][j]];
  }
  for (int i = 1; i <= m; i++) {
    map<int, int> ma;
    for (int j = 1; j <= n; j++) b[j] = mp[j][i];
    sort(b + 1, b + n + 1);
    for (int j = 1; j <= n; j++)
      if (!ma[b[j]]) ma[b[j]] = ++num2[i];
    for (int j = 1; j <= n; j++) l[j][i] = ma[mp[j][i]];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      printf("%d ",
             max(l[i][j], h[i][j]) + max(num[i] - h[i][j], num2[j] - l[i][j]));
    putchar('\n');
  }
  return 0;
}
