// Arup Guha
// 2/18/2024
// Solution to Kattis Problem: Exam Manipulation
// https://open.kattis.com/problems/exammanipulation

import java.util.*;

public class exammanipulation {

	public static int n;
	public static int nQ;
	public static int[][] answers;

	public static void main(String[] args) {

		// Read # of students and questions.
		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		nQ = stdin.nextInt();
		answers = new int[n][nQ];
		
		// Read in answers updating Trues to 1.
		for (int i=0; i<n; i++) {
			String tmp = stdin.next();
			for (int j=0; j<nQ; j++)
				if (tmp.charAt(j) == 'T')
					answers[i][j] = 1;
		}
		
		// Set up the odometer and go!
		int[] odom = new int[nQ];
		int res = odometer(odom, 0);
		System.out.println(res);
	}
	
	public static int scoreit(int[] correct) {
	
		int res = nQ;

		// Go through each student.
		for (int i=0; i<n; i++) 
			res = Math.min(res, score(correct, answers[i]));
		
		// This will be the lowest score of any student.
		return res;
	}
	
	// Returns the number of matching answers between cor and stud.
	public static int score(int[] cor, int[] stud) {
		int res = 0;
		for (int i=0; i<cor.length; i++)
			if (cor[i] == stud[i])
				res++;
		return res;
	}

	// Returns the best result with the first k items in this odometer (answer key)
	// fixed.
	public static int odometer(int[] list, int k) {

		// Done filling it in.
		if (k == list.length) return scoreit(list);
			
		// Try each possible item in slot k, in numeric order, and recurse.
		int res = 0;
		for (int i=0; i<2; i++) {
			list[k] = i;
			res = Math.max(res, odometer(list, k+1));
		}
		return res;
	}
}