output_description: Print the number of minimum times the bar needs to be cut so that every block
  after the cuts has K or less white squares.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      H W K
      S_{1,1}S_{1,2}...S_{1,W}
      :
      S_{H,1}S_{H,2}...S_{H,W}
attempt: # -*- coding: utf-8 -*-
  
  import sys
  from itertools import accumulate
  from bisect import bisect_right
  
  
  def input():
      return sys.stdin.readline().strip()
  
  
  def list2d(a, b, c):
      return [[c] * b for i in range(a)]
  
  
  def list3d(a, b, c, d):
      return [[[d] * c for j in range(b)] for i in range(a)]
  
  
  def list4d(a, b, c, d, e):
      return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
  
  
  def ceil(x, y=1):
      return int(-(-x // y))
  
  
  def INT():
      return int(input())
  
  
  def MAP():
      return map(int, input().split())
  
  
  def LIST(N=None):
      return list(MAP()) if N is None else [INT() for i in range(N)]
  
  
  def Yes():
      print("Yes")
  
  
  def No():
      print("No")
  
  
  def YES():
      print("YES")
  
  
  def NO():
      print("NO")
  
  
  sys.setrecursionlimit(10**9)
  INF = 10**18
  MOD = 10**9 + 7
  
  
  def build_grid(H, W, intv, _type, space=True, padding=False):
      # 入力がスペース区切りかどうか
      if space:
          _input = lambda: input().split()
      else:
          _input = lambda: input()
      _list = lambda: list(map(_type, _input()))
      # 余白の有無
      if padding:
          offset = 1
      else:
          offset = 0
      grid = list2d(H + offset * 2, W + offset * 2, intv)
      for i in range(offset, H + offset):
          row = _list()
          for j in range(offset, W + offset):
              grid[i][j] = row[j - offset]
      return grid
  
  
  def popcount(i):
      return bin(i).count("1")
  
  
  H, W, K = MAP()
  grid = build_grid(H, W, 0, int, space=0)
  
  ans = INF
  for S in range(1 << (H - 1)):
      N = popcount(S) + 1
      A = list2d(N, W, 0)
      for w in range(W):
          A[0][w] = grid[0][w]
      h = 0
      for k in range(H - 1):
          if S & 1 << k:
              h += 1
          for w in range(W):
              A[h][w] += grid[k + 1][w]
      for i in range(N):
          A[i] = [0] + list(accumulate(A[i]))
      cnt = 0
      idx = 1
      while 1:
          nxt = INF
          for i in range(N):
              nxt = min(nxt, bisect_right(A[i], K + A[i][idx - 1], lo=idx))
          if idx == nxt:
              cnt = INF
              break
          idx = nxt
          if idx == W + 1:
              break
          cnt += 1
      ans = min(ans, N - 1 + cnt)
  print(ans)
  
problem_description: Statement
  
  We have a chocolate bar partitioned into H horizontal rows and W vertical
  columns of squares.
  
  The square (i, j) at the i-th row from the top and the j-th column from the
  left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`.
  
  We will cut the bar some number of times to divide it into some number of
  blocks. In each cut, we cut the whole bar by a line running along some
  boundaries of squares from end to end of the bar.
  
  How many times do we need to cut the bar so that every block after the cuts
  has K or less white squares?
samples: [{"input": "3 5 4\n    11100\n    10001\n    00111", "output": "2\n    \n\nFor example, cutting between the 1-st and 2-nd rows and between the 3-rd and\n4-th columns - as shown in the figure to the left - works.\n\nNote that we cannot cut the bar in the ways shown in the two figures to the\nright.\n\n![Figure](https://img.atcoder.jp/ghi/ac90dd542639c04402125403b1c319d7.png)\n\n* * *"}, {"input": "3 5 8\n    11100\n    10001\n    00111", "output": "0\n    \n\nNo cut is needed.\n\n* * *"}, {"input": "4 10 4\n    1110010010\n    1000101110\n    0011101001\n    1101000111", "output": "3"}]