// Arup Guha
// 3/9/2024
// Solution to 2023 SER D1 Problem G: On-Call Team

using namespace std;

#include <bits/stdc++.h>

int solve(vector<vector<int>> &lists, int n, int k);
int getPeople(vector<vector<int>> &lists, int mask, vector<int>& smallCols, int numOn);
int numBits(int mask);

int main() {

    int n, k;
    cin >> n >> k;

    vector<vector<int>> lists(k);

    vector<string> input;
    for (int i=0; i<n; i++) {
        string tmp;
        cin >> tmp;
        input.push_back(tmp);
    }

    // For each column, store where there's a 1.
    // So for each task we store the workers that can do it.
    for (int j=0; j<k; j++)
        for (int i=0; i<n; i++)
            if (input[i][j] == '1')
                lists[j].push_back(i);

    // Solve it!
    cout << solve(lists, n, k) << endl;

    return 0;
}

// Return the answer lists stores info about each column.
// n is the number of people(rows), k is # of columns.
int solve(vector<vector<int>> &lists, int n, int k) {

    vector<int> smallCols;

    for (int i=0; i<k; i++)
        if (lists[i].size() < k)
            smallCols.push_back(i);

    // Get this easy case out of the way.
    int sz = smallCols.size();
    if (sz == 0) return k;

    int res = k;

    // Trying each subset of masks.
    for (int mask=1; mask<(1<<sz); mask++) {

        // How many tasks in this subset.
        int numOn = numBits(mask);

        // The number of people who can do at least one of these tasks.
        int numPeople = getPeople(lists, mask, smallCols, numOn);

        // If this is true, then numPeople is the most the answer could be.
        if (numPeople < numOn && numPeople < res)
            res = numPeople;
    }

    return res;
}

// Returns the number of people who can cover at least one task in mask.
int getPeople(vector<vector<int>> &lists, int mask, vector<int>& smallCols, int numOn) {

    vector<int> total;

    // Go through the mask.
    for (int i=0;; i++) {
        if ((1<<i) > mask) break;
        if ( ((1<<i) & mask) == 0) continue;

        // Bit i is included, which really means column smallCols[i].
        for (int x: lists[smallCols[i]]) {

            // see if x is a new person who can do task smallCols[i].
            bool need = true;
            for (int z=0; z<total.size(); z++)
                if (total[z] == x)
                    need = false;

            // Add x because she's a new person.
            if (need) total.push_back(x);

            // We only care if this answer is less than numOn...
            // This saves on run time.
            if (total.size() >= numOn) return total.size();
        }
    }

    // Ta da!
    return total.size();
}

// Returns the number of bits on on mask.
int numBits(int mask) {
    int res = 0;
    for (int i=0;;i++) {
        if ((1<<i) > mask) break;
        if (mask & (1<<i)) res++;
    }
    return res;
}
