Under construction

Still being built. Things may change

Pilots

Time limit3sMemory limit128 MB

Summary
Find the length of the longest contiguous fragment whose maximum minus minimum is at most t.
Level

Medium4 of 10

Topics
Sliding window, Two pointers, Queue
Solved
No attempts yet

Problem

At the Byteotian Training Centre, pilots train for missions that demand extraordinary precision and control. One measure of a pilot's skill is how long they can fly a desired route without deviating too much, that is, how steadily they can hold their course.

The task is hard because the simulator is extremely sensitive: it records even the slightest movement of the yoke (the control device used to steer an aircraft). At every moment the simulator stores a single integer describing the yoke's position.

Before each session a tolerance level tt is fixed. The pilot must then fly for as long as possible so that every recorded yoke position stays within tt of every other. Formally, the flight fragment from moment ii to moment jj is within tolerance tt when the measurements ai,ai+1,…,aja_i, a_{i+1}, \dots, a_j satisfy ∣ak−al∣≤t|a_k - a_l| \le t for every pair of elements ak,ala_k, a_l in it.

Given the tolerance level and the sequence of yoke position measurements, determine the length of the longest flight fragment that stays within the tolerance level tt.

Input

The first line contains two integers tt and nn (0≤t≤2 000 000 0000 \le t \le 2\,000\,000\,000, 1≤n≤3 000 0001 \le n \le 3\,000\,000), separated by a single space: the tolerance level and the number of recorded measurements.

The second line contains those nn measurements separated by single spaces. Each measurement is an integer between 11 and 2 000 000 0002\,000\,000\,000.

Output

Print a single integer: the maximum length of a flight fragment that stays within the given tolerance level tt.

Examples1

  1. Example 1

    Input
    3 9
    5 1 3 5 8 6 6 9 10
    
    Expected output
    4