This page is still under construction.

Parts of this page are still being built. What you see may change.

Making Lunch Boxes

Time limit8sMemory limit512 MB

Summary
Given binary recipe vectors, choose the largest subset with every ingredient appearing in an even number of chosen recipes, meaning their XOR is zero.
Level

Hard8 of 10

Topics
Math, Bit manipulation, Greedy
Solved
No attempts yet

Problem

Taro has been hooked on making lunch boxes lately. He got a new lunch box recipe book today, and he wants to try as many of the recipes in it as he can in one day.

He has plenty of every ingredient, but they all come in vacuum packs of two. If he opens a pack, uses one piece and leaves the other, the leftover goes bad quickly. Making two lunch boxes from the same recipe is no fun. So Taro decided to pick a set of recipes that are all different and leave no ingredient unused. An ingredient is used up pack by pack exactly when the number of chosen recipes that need it is even.

The book may list different recipes that call for the same set of ingredients. Those still count as different recipes.

He may pick no recipe at all, and then the answer is 0. How many recipes can Taro try today at most?

Input

The input consists of at most 50 datasets, each in the following format.

n m
b1,1...b1,m
...
bn,1...bn,m

The first line contains nn, the number of recipes listed in the book, and mm, the number of ingredients. Both nn and mm are positive integers with 1≤n≤5001 \le n \le 500, 1≤m≤5001 \le m \le 500 and 1≤n×m≤5001 \le n \times m \le 500. Each of the next nn lines describes one recipe as a string of length mm made of 0 and 1. If bi,jb_{i,j} is 1, the ii-th recipe needs the jj-th ingredient, and if it is 0, it does not. Every such line contains at least one 1.

The end of the input is a line containing two zeros.

Output

For each dataset, print the maximum number of recipes Taro can try, one per line.

Examples2

  1. Example 1

    Input
    4 3
    110
    101
    011
    110
    7 1
    1
    1
    1
    1
    1
    1
    1
    4 5
    10000
    01000
    00100
    00010
    6 6
    111111
    011000
    100000
    000010
    100001
    100100
    0 0
    
    Expected output
    3
    6
    0
    6
    
  2. Example 2

    Input
    2 2
    10
    10
    3 2
    11
    10
    01
    0 0
    
    Expected output
    2
    3