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: def create_groups(H):
      F = "{:0" + str(H) + "b}"
      ret = set()
      for n in range(2**H):
          g = create_group(F.format(n))
          ret.add(tuple(g))
      return list(sorted(ret))
  
  
  def create_group(s):
      ret = []
      n = 0
      for i in range(len(s)):
          if i == 0:
              ret.append(0)
          else:
              if s[i - 1] == s[i]:
                  ret.append(n)
              else:
                  n += 1
                  ret.append(n)
      return ret
  
  
  # assert(create_group("0000") == [0,0,0,0])
  # assert(create_group("0011") == [0,0,1,1])
  # assert(create_group("0010") == [0,0,1,2])
  
  # print(len(create_groups(10)))
  
  
  def solve(H, W, K, fields):
      ans = H * W + 1
      for g in create_groups(H):
          M = len(set(g))
          s = [0 for _ in range(M)]
          tans = M - 1
          for w in range(W):
              for h in range(H):
                  if fields[h][w] == "1":
                      s[g[h]] += 1
              if any([a > K for a in s]):
                  s = [0 for _ in range(M)]
                  tans += 1
                  for h in range(H):
                      if fields[h][w] == "1":
                          s[g[h]] += 1
              if any([a > K for a in s]):
                  tans = H * W + 1
                  break
          ans = min(ans, tans)
      return ans
  
  
  #
  # assert(solve(3, 3, 1, ["111", "111", "111"]) == 4)
  # assert(solve(1, 1, 1, ["1"]) == 0)
  # assert(solve(2, 1, 1, ["1", "1"]) == 1)
  # assert(solve(1, 2, 1, ["11"]) == 1)
  # assert(solve(1, 2, 1, ["11"]) == 1)
  # assert(solve(3, 5, 4, ["11100", "10001", "00111"]) == 2)
  # assert(solve(3, 5, 8, ["11100", "10001", "00111"]) == 0)
  # assert(solve(4, 10, 4, ["1110010010", "1000101110", "0011101001", "1101000111"]) == 3)
  
  # print(slowsolve(5, 11, "33883"))
  # print(solve(5, 11, "33883"))
  
  if __name__ == "__main__":
      H, W, K = tuple(map(int, input().split(" ")))
      fields = []
      for _ in range(H):
          fields.append(input())
      print(solve(H, W, K, fields))
  
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"}]