//Problem "Matrix"
//8th Internet Olympiad, season 2007-2008
//Problem Author:  Fedor Tsarev, tsarev@rain.ifmo.ru
//Solution Author: Vladimir Ulyantsev, ulyantsev@rain.ifmo.ru

import java.io.*;
import java.util.*;

public class matrix_vu implements Runnable {
	final static String FILE = "matrix";
	
	public static void main(String[] args) {
		Locale.setDefault(Locale.US);
		new Thread(new matrix_vu()).start();
	}
	
	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;
	
	int nextInt() throws IOException {
		while (st == null || !st.hasMoreElements()) {
			st = new StringTokenizer(in.readLine());
		}
		return Integer.parseInt(st.nextToken());
	}
	
	public matrix_vu() {
		try {
			in = new BufferedReader(new FileReader(FILE + ".in"));
			out = new PrintWriter(new File(FILE + ".out"));
			st = new StringTokenizer("");
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
	
	public void run() {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		} finally {
			out.close();
		}
	}
	
	private void myAssert(boolean e) {
		if (!e) {
			throw new Error("Author failure!!!");
		}
	}
	
	public void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();

		myAssert(1 <= n && n <= 750 && 1 <= m && m <= 750);
		int[][] k = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				k[i][j] = nextInt();
				myAssert(-1000 <= k[i][j] && k[i][j] <= 1000);
			}
		}

		int[] min = new int[n];
		for (int i = 0; i < n; i++) {
			for (int j = 1; j < m; j++) {
				if (k[i][j] < k[i][min[i]]) {
					min[i] = j;
				}
			}
		}
		
		int[] max = new int[m];
		for (int i = 1; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (k[i][j] > k[max[j]][j]) {
					max[j] = i;
				}
			}
		}

		int ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (k[i][j] == k[max[j]][j] && k[i][j] == k[i][min[i]]) {
					ans++;
				}
			}
		}
		out.print(ans);
	}
	
}
