#P30. [KBC001E] Difference

[KBC001E] Difference

Source

This problem is adapted from Long Long OJ. All rights reserved.

Description

Given n,kn,k, and sequences a,ba,b, find the shortest interval [i,j][i,j] such that:

(minp=ijap)+kmaxp=ijbp(\min_{p=i}^ja_p)+k\leq\max_{p=i}^jb_p

Output the length of the interval.

Output 1-1 if no interval is found.

Input

The first line consists of two integers nn and kk.

The second line consists of nn integers a1,a2,,ana_1,a_2,\ldots,a_n.

The third line consists of nn integers b1,b2,,bnb_1,b_2,\ldots,b_n.

Output

An integer that represents the minimum length of interval.

Output 1-1 if no interval is found.

Samples

5 10
8 7 14 8 3
4 2 5 8 2
-1
5 14
11 22 3 15 6
21 20 17 22 136
1

Tips

Sample Explanation 2:

The interval is [3,3][3,3] or [5,5][5,5], because a3+k=3+14=17a_3+k=3+14=17 and a5+k=6+14=20<136a_5+k=6+14=20\lt136.


  • 1n1051\le n\le 10^5.
  • 1k,ai,bi1061\le k,a_i,b_i\le 10^6.