#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= f;
}
template <class T>
inline void umin(T &x, T y) {
  x = x < y ? x : y;
}
template <class T>
inline void umax(T &x, T y) {
  x = x > y ? x : y;
}
inline unsigned int R() {
  static unsigned int seed = 416;
  return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13;
}
const int N = 1020;
int n, m, a[N][N];
struct QQ {
  int s[N], n;
  void init(int *a, int nn) {
    n = nn;
    for (register int i = (1); i <= (n); i++) s[i] = a[i];
    sort(s + 1, s + n + 1);
    n = unique(s + 1, s + n + 1) - s - 1;
  }
  int q(int x) { return lower_bound(s + 1, s + n + 1, x) - s; }
  int query1(int x) { return q(x) - 1; }
  int query2(int x) { return n - q(x); }
} l[N], r[N];
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]);
  static int s[N];
  for (register int i = (1); i <= (n); i++) {
    for (register int j = (1); j <= (m); j++) s[j] = a[i][j];
    l[i].init(s, m);
  }
  for (register int j = (1); j <= (m); j++) {
    for (register int i = (1); i <= (n); i++) s[i] = a[i][j];
    r[j].init(s, n);
  }
  for (register int i = (1); i <= (n); i++) {
    for (register int j = (1); j <= (m); j++) {
      printf("%d ", 1 + max(l[i].query1(a[i][j]), r[j].query1(a[i][j])) +
                        max(l[i].query2(a[i][j]), r[j].query2(a[i][j])));
    }
    puts("");
  }
  return 0;
}
