import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
public class Main {
private static Reader reader;
public static void main(String[] args) {
reader = new InputStreamReader(System.in);
int n = getInt();
int m = getInt();
int a[] = new int[n];
int b[][] = new int[n][m];
for (int i = 0; i < m; i++) {
b[0][i] = getInt();
}
int fif = 1;
a[0] = 1;
for (int i = 1; i < n; i++) {
a[i] = 1;
for (int j = 0; j < m; j++) {
b[i][j] = getInt();
}
for (int w = i-1; w >= 0; w--) {
boolean boo = true;
for (int j = 0; j < m; j++) {
if(b[i][j]>=b[w][j]) {
boo = false;
}
}
if(boo) {
int k = a[w]+1;
a[i] = k>a[i]?k:a[i];
}
}
if(a[i]>fif) fif = a[i];
}
System.out.println(n-fif);
}
public static int getInt() {
int res = 0, read;
try {
while ((read = reader.read()) != -1) {
if (Character.isDigit(read)) {
res = read - '0';
while ((read = reader.read()) != -1) {
if (Character.isDigit(read)) {
res = res * 10 + (read - '0');
} else {
break;
}
}
break;
}
}
} catch (IOException e) {
e.printStackTrace();
}
return res;
}
}
这道题是线性的动态规划,类似于经典题目《拦截导弹》