Farmer John's $N$ cows ($1 \le N \le 5{,}000$) each have a unique positive integer brand that fits into a signed 32-bit integer. He wishes the cows would line up in numerical order for feeding, but they never cooperate.
To encourage good behavior, he allows a cow to eat only if it is the first cow chosen to eat, or if its brand is greater than the brand of the cow that ate immediately before it. Cows must be chosen in the order they stand in line (from left to right), though some may be skipped.
Given the list of cow brands in the order they stand in line, what is the largest number of cows that can be fed under Farmer John's rules?
For example, consider this line of 11 cows:
2 5 18 3 4 7 10 9 11 8 15
One could feed the cows in the order 2, 3, 4, 7, 10, 11, and 15 for a total of seven fed, the largest number possible.
One could not feed the cows in the order 2, 5, 3, 10, 15, since cow 3's brand is not greater than that of its predecessor, 5.