TITLE: How long does a sequence need to be to be guaranteed to have a monotonic subsequence length k?
QUESTION [6 upvotes]: The sequence 7, 2, 4, 1, 4, 8 has an increasing subsequence length four (2, 4, 4, 8) and a decreasing subsequence length three (7, 4, 1). It has other monotonic (increasing or decreasing) subsequences too, but none longer than four.
How long does a sequence need to be to be guaranteed to have a monotonic subsequence length k?

REPLY [6 votes]: The search term for background on the question and the other answers is 

Erdos-Szekeres theorem (on monotone subsequences).

The theorem, with several remarkable proofs and generalizations, is that a sequence of length $mn+1$ has an increasing subsequence $m+1$ long, or a length $n+1$ decreasing subsequence.
To the stated question,

How long does a sequence need to be to be guaranteed to have a monotonic subsequence length $k$?

the answer is that the E-S bound of $mn+1$ is the minimum needed to guarantee $(m+1,n+1)$.  Thus for $(n,n)$ the minimum length is $(n-1)^2+1$ and there are sequences of length $(n-1)^2$ with no monotone subsequence of length $n$.  Earlier question on that:
Why is Erdős–Szekeres theorem sharp?