#include <bits/stdc++.h>
using namespace std;
int a[1000][1000];
int rr[1000][1000], cr[1000][1000], rc[1000], cc[1000];
class ASkyscrapers {
 public:
  void solve(std::istream& cin, std::ostream& cout) {
    int n, m;
    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++) {
      set<int> s;
      for (int j = 0; j < m; j++) s.insert(a[i][j]);
      rc[i] = s.size();
      map<int, int> mp;
      int ct = 1;
      for (int x : s) mp[x] = ct++;
      for (int j = 0; j < m; j++) rr[i][j] = mp[a[i][j]];
    }
    for (int j = 0; j < m; j++) {
      set<int> s;
      for (int i = 0; i < n; i++) s.insert(a[i][j]);
      cc[j] = s.size();
      map<int, int> mp;
      int ct = 1;
      for (int x : s) mp[x] = ct++;
      for (int i = 0; i < n; i++) cr[i][j] = mp[a[i][j]];
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (rr[i][j] < cr[i][j]) {
          cout << max(cr[i][j] - rr[i][j] + rc[i], cc[j]) << " ";
        } else {
          cout << max(rr[i][j] - cr[i][j] + cc[j], rc[i]) << " ";
        }
      }
      cout << endl;
    }
  }
};
int main() {
  ASkyscrapers solver;
  std::ios::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
