TITLE: Erdős-Szekeres for first differences
QUESTION [22 upvotes]: The classical Erdős-Szekeres theorem says that any sequence of $n^2+1$
real numbers contains a monotonic $(n+1)$-term subsequence. Suppose, however,
that we want to find a subsequence which is not necessarily
monotonic itself, but has the sequence of its first differences monotonic.
How long has the original sequence to be to ensure that such an $(n+1)$-term
subsequence can be found?

For positive integer $n$, what is the smallest integer $N=N(n)$ such that every
  $N$-element sequence of real numbers contains an $n$-element subsequence
  $(a_1,\ldots,a_n)$ with either $a_2-a_1\le\dotsb\le a_n-a_{n-1}$, or
  $a_2-a_1\ge\dotsb\ge a_n-a_{n-1}$?

Trivially, we have $N(1)=1$, $N(2)=2$, and $N(3)=3$. However, I do not know
the value of $N(4)$.

The state of the art as of 05.03.12. The nice argument of Boris Bukh (below) shows that $N(n)$ is exponential in $n$. Still, this does not completely settle the problem.
Updated 16.03.12: the absolutely beautiful, must-upvote solution by Sergey Norin is posted below.

REPLY [21 votes]: For brevity let me call a sequence with non-decreasing first differences convex, and  a sequence with non-increasing first differences concave.
Let $M(r,s)$ denote the minimum integer $N$ so that every $N$-element sequence of real numbers contains a convex subsequence of length $r+1$ or a concave subsequence of length $s+1$. Below I attempt to show that

$$M(r,s)=\binom{r+s-2}{r-1}+1.$$

The lower bound: Let $[m]$ denote the set $\{1,\ldots,m\}$. 
For $S \subseteq [r+s-2]$, let $x_S := \sum_{i \in S}3^i$. Consider the sequence $(x_S\;|\; S \subseteq [r+s-2], |S|=s-1)$ with elements in increasing order. It has $\binom{r+s-2}{r-1}$ elements. We will show that this sequence contains no  convex subsequence of length $r+1$ and no concave subsequence of length $s+1$.
Let $x_{S_1},x_{S_2}, \ldots,x_{S_n}$  be a convex subsequence. Let $d_i$ be the maximum element of $S_{i+1} \setminus S_{i}$. Then $ 3^{d_i}/2 < x_{S_{i+1}}-x_{S_i}< 3^{d_i+1}/2.$ It follows that $(d_1,d_2,\ldots,d_{n-1})$ is a strictly increasing sequence, and that $d_i \not \in S_1$ for $i \in [n-1]$. Therefore $n \leq r$ as desired. 
The proof showing that there is no concave subsequence of length $s+1$ is symmetric. (One can replace $x_{S_i}$ by $x_{[r+s-2]}-x_{S_i}$.)
The upper bound: The goal is to imitate the elegant pigeonhole argument of Seidenberg for Erdős-Szekeres theorem. (See e.g. Wikipedia.) 
Let $N = \binom{r+s-2}{r-1}+1$. Let ${\bf a}=(a_1,\ldots, a_N)$ be a sequence. 
For $i \in [N]$ and $k \in [r-1]$ let $\alpha_i(k)$ be the minimum real number so that a $(k+1)$-term convex subsequence of ${\bf a}$ ending with $a_i$ has $\alpha_i(k)$ as the difference of the last two terms. Set $\alpha_i(k)=+\infty$ if no such subsequence exists.
Note that for fixed $i$ the sequence $\alpha_i(\cdot)$ is non-decreasing.
Analogously, for $k \in [s-1]$ we define $\beta_i(k)$ to be the maximum real number so that a $(k+1)$-term concave subsequence of ${\bf a}$ ending with $a_i$ has $\beta_i(k)$ as the difference of the last two terms. Set $\beta_i(k)=-\infty$ if no such subsequence exists.
The sequence $\beta_i(\cdot)$ is non-increasing.
For given $i$ arrange the elements of the multiset $\{\alpha_i(1),\ldots, \alpha_i(r-1),\beta_i(1),\ldots,\beta_i(s-1)\}$ in increasing order, with alphas preceding betas, when the values are the same. Now we consider the resulting sequence as a sequence of $r+s-2$ symbols each of which is either $\alpha$ or $\beta$, ignoring the indexing. Call this sequence $\bf \chi_i$. For example, we always have
$${\bf \chi_1}=(\beta, \ldots,\beta, \alpha, \ldots, \alpha),$$
$${\bf \chi_2}=(\beta,\ldots,\beta, \alpha, \beta, \alpha, \ldots, \alpha),$$
and ${\bf \chi_3}$ depends on $a_1$, $a_2$ and $a_3$. 
There are $N-1$ possible sequences and by 
pigeonhole principle we have ${\bf \chi_i}={\bf \chi_j}$ for some $1 \leq i < j \leq N$. Let $z=a_j-a_i$. Let $r'$ be chosen to be maximum so that $\alpha_{i}(r') \leq z$, and let $r'=0$ if no such $r'$ exists. Let $s'$ be chosen to be maximum so that $\beta_{i}(s') \geq z$, and let $s'=0$ if no such $s'$ exists. Note that $\alpha_{j}(r'+1) \leq z$ and $\beta_{j}(s'+1) \geq z$. If $r'=r-1$ or $s'=s-1$ then $\bf{a}$ contains a  convex subsequence of length $r+1$ or a concave subsequence of length $s+1$ as desired. Otherwise, $r'+1$ alphas precede $s'+1$ betas in $\chi_j$,
while in $\chi_i$ after the first $r'+1$ alphas we encounter only $\leq s'$ betas.
This contradiction finishes the proof.