#include <bits/stdc++.h>
template <typename T>
inline T max(const T a, const T b) {
  return a > b ? a : b;
}
template <typename T>
inline T min(const T a, const T b) {
  return a < b ? a : b;
}
template <typename T>
inline void mind(T& a, const T b) {
  a = a < b ? a : b;
}
template <typename T>
inline void maxd(T& a, const T b) {
  a = a > b ? a : b;
}
template <typename T>
inline T abs(const T a) {
  return a > 0 ? a : -a;
}
template <typename T>
inline void swap(T& a, T& b) {
  T c = a;
  a = b;
  b = c;
}
template <typename T>
inline T gcd(const T a, const T b) {
  if (!b) return a;
  return gcd(b, a % b);
}
template <typename T>
inline T lcm(const T a, const T b) {
  return a / gcd(a, b) * b;
}
template <typename T>
inline T square(const T x) {
  return x * x;
};
template <typename T>
inline void read(T& x) {
  char cu = getchar();
  x = 0;
  bool fla = 0;
  while (!isdigit(cu)) {
    if (cu == '-') fla = 1;
    cu = getchar();
  }
  while (isdigit(cu)) x = x * 10 + cu - '0', cu = getchar();
  if (fla) x = -x;
}
template <typename T>
inline void printe(const T x) {
  if (x >= 10) printe(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
inline void print(const T x) {
  if (x < 0)
    putchar('-'), printe(-x);
  else
    printe(x);
}
int n, m, a[1001][1001], b[1001][1001], c[1001][1001], d[1001][1001];
int h[1001], l[1001];
int main() {
  read(n), read(m);
  for (register int i = 1; i <= n; i++)
    for (register int j = 1; j <= m; j++)
      read(a[i][j]), b[i][j] = a[i][j], c[j][i] = a[i][j];
  for (register int i = 1; i <= n; i++) {
    std::sort(b[i] + 1, b[i] + m + 1);
    int tot = std::unique(b[i] + 1, b[i] + m + 1) - b[i] - 1;
    h[i] = tot;
    for (register int j = 1; j <= m; j++)
      d[i][j] = std::lower_bound(b[i] + 1, b[i] + tot + 1, a[i][j]) - b[i];
  }
  for (register int i = 1; i <= m; i++) {
    std::sort(c[i] + 1, c[i] + n + 1);
    int tot = std::unique(c[i] + 1, c[i] + n + 1) - c[i] - 1;
    l[i] = tot;
    for (register int j = 1; j <= n; j++)
      a[j][i] = std::lower_bound(c[i] + 1, c[i] + tot + 1, a[j][i]) - c[i];
  }
  for (register int i = 1; i <= n; i++) {
    for (register int j = 1; j <= m; j++) {
      print(max(d[i][j] - 1, a[i][j] - 1) + 1 +
            max(h[i] - d[i][j], l[j] - a[i][j])),
          putchar(' ');
    }
    putchar('\n');
  }
  return 0;
}
