Making Lunch Boxes

Taro has been hooked on making lunch boxes recently. Taro has obtained a new lunch box recipe book today, and wants to try as many of the recipes listed in the book as possible.

Enough of the ingredients for all the recipes are at hand, but they all are in vacuum packs of two. If only one of them is used leaving the other, the leftover will be rotten easily, but making two of the same recipe is not interesting. Thus he decided to make a set of lunch boxes, each with different recipe, that wouldn't leave any unused ingredients.

Note that the book may include recipes for different lunch boxes made of the same set of ingredients.

How many lunch box recipes can Taro try today at most following his dogma?

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 n, which is the number of recipes listed in the book, and m, which is the number of ingredients. Both n and m are positive integers and satisfy 1 ≤ n ≤ 500, 1 ≤ m ≤ 500 and 1 ≤ n × m ≤ 500. The following n lines contain the information for each recipe with the string of length m consisting of 0 or 1. bi,j implies whether the i-th recipe needs the j-th ingredient. 1 means the ingredient is needed for the recipe and 0 means not. Each line contains at least one 1.

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

Output

For each dataset, output the maximum number of recipes Taro can try.

Sample 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


Output for the Sample Input


3
6
0
6






Example

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


Output

3
6
0
6

Source: aizu | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import time, random, resource
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	rr = []

	def f():
		(n, m) = LI()
		if n == 0:
			return
		bb = [int(S(), 2) for _ in range(n)]
		bc = collections.defaultdict(int)
		for i in bb:
			bc[i] += 1
		rt = 0
		b = []
		for (k, v) in bc.items():
			if v > 2:
				if v % 2 == 0:
					rt += v - 2
					v = 2
				else:
					rt += v - 1
					v = 1
			for i in range(v):
				b.append(k)
		n = len(b)
		c = collections.defaultdict(int)
		c[0] = 0
		for i in b:
			for (k, v) in list(c.items()):
				t = k ^ i
				if c[t] <= v:
					c[t] = v + 1
		rr.append(c[0] + rt)
		return True
	while f():
		pass
	return JA(rr, '\n')
print(main())


import sys
from collections import defaultdict

def solve(n, m):
	b = [int(sys.stdin.readline(), 2) for i in range(n)]
	if n < m:
		M = 1 << n
		ans = 0
		for i in range(M):
			k = 0
			s = 0
			for j in range(n):
				if i & 1 << j:
					k ^= b[j]
					s += 1
			if not k:
				if s > ans:
					ans = s
		print(ans)
	else:
		dp = defaultdict(lambda : 0)
		dp[0] = 0
		for i in b:
			d = dp.copy()
			for j in d.keys():
				j_ = i ^ j
				if d[j] + 1 > dp[j_]:
					dp[j_] = d[j] + 1
		print(dp[0])
while 1:
	(n, m) = [int(x) for x in sys.stdin.readline().split()]
	if n == 0:
		break
	solve(n, m)


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10 ** 9 + 7
inf = float('inf')

def I():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))
while 1:
	(n, m) = LI()
	if n == 0 and m == 0:
		quit()
	recipe = []
	for _ in range(n):
		c = list(map(int, list(input())))
		s = 0
		t = 1
		for i in range(m):
			s += c[m - i - 1] * t
			t *= 2
		recipe.append(s)
	dp = defaultdict(int)
	dp[0] = 0
	for r in recipe:
		dp1 = defaultdict(int)
		for (j, k) in dp.items():
			dp1[j] = k
		for (j, k) in dp.items():
			dp1[j ^ r] = max(dp1[j ^ r], k + 1)
		dp = dp1
	print(dp[0])


while 1:
	(n, m) = map(int, input().split())
	if n == m == 0:
		break
	B = [int(input(), 2) for i in range(n)]
	C = {0: 0}
	for b in B:
		D = dict(C)
		for k in C:
			D[k ^ b] = max(D.get(k ^ b, 0), C[k] + 1)
		C = D
	print(C[0])


from collections import defaultdict

def main(n, m):
	b = [int('0b' + input(), 0) for i in range(n)]
	ans = 0
	d = defaultdict(int)
	d[0] = 0
	for i in b:
		nd = defaultdict(int)
		for (k, v) in d.items():
			nd[k] = v
		for (key, value) in d.items():
			nd[key ^ i] = max(nd[key ^ i], value + 1)
		d = nd
	print(d[0])
while 1:
	(n, m) = map(int, input().split())
	if n == 0:
		break
	main(n, m)


iipt = lambda : int(input())
miipt = lambda : list(map(int, input().split()))
from pprint import pprint
r = []
n = m = 0

def solven(k, i):
	if i == n:
		return -1 if k else 0
	s1 = solven(k ^ r[i], i + 1)
	if s1 != -1:
		s1 += 1
	return max(s1, solven(k, i + 1))
while True:
	(n, m) = miipt()
	if n == m == 0:
		break
	r = [int(input(), 2) for i in range(n)]
	if n < 22:
		print(solven(0, 0))
	else:
		dp = {}
		dp[0] = 0
		for i in range(n):
			dp_ = dp.copy()
			for (k, v) in dp_.items():
				if k ^ r[i] in dp:
					dp[k ^ r[i]] = max(dp[k ^ r[i]], v + 1)
				else:
					dp[k ^ r[i]] = v + 1
		print(dp[0])


while 1:
	(n, m) = map(int, input().split())
	if n + m == 0:
		break
	B = [int(input(), 2) for i in range(n)]
	C = {0: 0}
	for b in B:
		(*D,) = C.items()
		for (k, v) in D:
			C[k ^ b] = max(C.get(k ^ b, 0), v + 1)
	print(C[0])


while 1:
	(n, m) = map(int, input().split())
	if n + m == 0:
		break
	C = {0: 0}
	for i in range(n):
		b = int(input(), 2)
		for (k, v) in dict(C).items():
			if C.get(k ^ b, 0) < v + 1:
				C[k ^ b] = v + 1
	print(C[0])


def make(n):
	C = {0: 0}
	for i in range(n):
		b = int(input(), 2)
		for (k, v) in dict(C).items():
			if C.get(k ^ b, 0) < v + 1:
				C[k ^ b] = v + 1
	return C

def calc(P, Q):
	yield 0
	for (k, v) in P.items():
		if k in Q:
			yield (v + Q[k])

def solve():
	while 1:
		(n, m) = map(int, input().split())
		if n + m == 0:
			break
		yield max(calc(make(n // 2), make(n - n // 2)))
print(*solve(), sep='\n')


while 1:
	(n, m) = map(int, input().split())
	if n + m == 0:
		break
	B = [int(input(), 2) for i in range(n)]
	C = {0: 0}
	for b in B:
		D = dict(C)
		for (k, v) in D.items():
			C[k ^ b] = max(C.get(k ^ b, 0), v + 1)
	print(C[0])


ans = []
while 1:
	(n, m) = map(int, input().split())
	if n + m == 0:
		break
	C = {0: 0}
	for i in range(n):
		b = int(input(), 2)
		for (k, v) in dict(C).items():
			if C.get(k ^ b, 0) < v + 1:
				C[k ^ b] = v + 1
	ans.append(C[0])
print(*ans, sep='\n')