#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let h: usize = sc.cin();
    let w: usize = sc.cin();
    let k: usize = sc.cin();

    let a: Vec<Vec<bool>> = (0..h).map(|_| {
        sc.chars().iter().map(|&c| c == '1').collect()
    }).collect();
    // trace!(&a);

    let mut ans = h + w;

    for I in 0..(1<<(h-1)) {
        let mut groups: Vec<Vec<usize>> = vec![vec![]];
        for i in 0..h {
            let last = groups.len() - 1;
            groups[last].push(i);
            if i < h - 1 && (I & (1 << i) > 0) {
                groups.push(vec![]);
            }
        }
        // trace!(&groups);

        let m = groups.len();
        let mut count = vec![0; m];

        let mut op = 0;
        let mut ng = false;

        for j in 0..w {
            let mut ok = true;
            for d in 0..m {
                for &i in groups[d].iter() {
                    if a[i][j] {
                        count[d] += 1;
                        if count[d] > k { ok = false; }
                    }
                }
            }
            if !ok {
                op += 1;
                for d in 0..m {
                    count[d] = 0;
                    for &i in groups[d].iter() {
                        if a[i][j] {
                            count[d] += 1;
                            if count[d] > k { ng = true; }
                        }
                    }
                }
            }
            if ng { break }
        }
        if !ng {
            ans = min!(ans, op + m - 1);
        }
    }
    put!(ans);

}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 4352