#include <iostream>
#include <fstream>
std::ifstream f("bac.txt");
int main(){
int m, n, a[100][100];
f >> m >> n;
int minim, maxim, linMax, linMin;
for (int i = 0; i < m; i++)
for(int j = 0; j < n; j++) {
f >> a[i][j];
if (i == 0 && j == 0)
minim = maxim = a[i][j];
else {
if (a[i][j] < minim) {
minim = a[i][j];
linMin = i;}
if (a[i][j] > maxim) {
maxim = a[i][j];
linMax = i;}
}
}
for(int i = 0; i < n; i++)
std::swap(a[linMin][i], a[linMax][i]);
for(int i = 0; i < m; i++) {
for(int j = 0; j < n; j++)
std::cout << a[i][j] << " ";
std::cout << "\n";
}
}