Under construction

Still being built. Things may change

Zip-line

Time limit3sMemory limit1024 MB

Summary
For each assumption that one tree has a new height, find the longest strictly increasing subsequence of the trees after that single change.
Level

Hard8 of 10

Topics
Dynamic programming, Binary search, Sorting
Solved
No attempts yet

Problem

Vasya has decided to build a zip-line on trees of a nearby forest. He wants the line to be as long as possible, but he does not remember the heights of all trees in the forest exactly. He is sure that he remembers the correct heights of all trees except, possibly, one of them.

The forest has nn trees in a row, numbered from left to right with integers from 11 to nn. According to Vasya, the height of the ii-th tree is hih_i. A zip-line of length kk (1≤k≤n1 \le k \le n) hangs over kk trees i1,i2,…,iki_1, i_2, \ldots, i_k (i1<i2<…<iki_1 < i_2 < \ldots < i_k) whose heights form an increasing sequence, that is, hi1<hi2<…<hikh_{i_1} < h_{i_2} < \ldots < h_{i_k}. The length of a zip-line is the number of trees that form it.

Petya was in the forest with Vasya and has qq assumptions about the mistake in Vasya's sequence hh. His ii-th assumption consists of two integers aia_i and bib_i, meaning that according to Petya, the height of tree aia_i is actually bib_i. Petya's assumptions are independent of each other.

For each of the qq assumptions, find the maximum length of a zip-line that can be built over the trees under that assumption.

Input

The first line contains two integers nn and mm (1≤n,m≤400 0001 \le n, m \le 400\,000), the number of trees and the number of Petya's assumptions. The next line contains nn integers hih_i (1≤hi≤1091 \le h_i \le 10^9), the heights of the trees according to Vasya. Each of the next mm lines contains two integers aia_i and bib_i (1≤ai≤n1 \le a_i \le n, 1≤bi≤1091 \le b_i \le 10^9).

Output

For each of Petya's assumptions, output one integer: the maximum length of a zip-line that can be built under that assumption.

Hint

Consider the first sample. The first assumption actually coincides with the height remembered by Vasya. In the second assumption the heights of the trees are (4,2,3,4)(4, 2, 3, 4), in the third one they are (1,2,3,3)(1, 2, 3, 3) and in the fourth one they are (1,2,3,5)(1, 2, 3, 5).

Examples2

  1. Example 1

    Input
    4 4
    1 2 3 4
    1 1
    1 4
    4 3
    4 5
    
    Expected output
    4
    3
    3
    4
    
  2. Example 2

    Input
    4 2
    1 3 2 6
    3 5
    2 4
    
    Expected output
    4
    3