Marbles

아직 제출이 없습니다시간 제한2초메모리 제한128 MB

문제

You are given a track of length LL. On it there are NN marbles at positions A_1,A_2,A_NA\_1,A\_2\cdots,A\_N  and NN switches at positions B_1,B_2,,B_NB\_1,B\_2,\cdots,B\_N, both of negligably small size. In the beginning, you direct each marble left or right and they all start moving at the constant speed of 11 in the given direction. When two marbles collide, they bounce off each other elastically, meaning that they continue moving in opposite directions at the same speed. If a marble collides with the beginning or end of the track it bounces off with the same speed in the opposite direction. Keep in mind that it takes exactly one second for a marble at position ii to travel to the position i+1i+1 or i1i-1, and it also takes exactly one second to travel from 11 back to 11 while changing directions, or to travel from LL back to LL while changing directions. Note that marbles never stop on the switches.

The goal is to have a marble on top of every switch, i.e. to have all marbles simultaneously on the corresponding switches.

You need to find the minimum amount of time needed to achieve this.

입력

In the first line of input you are given LL (L109L\le 10^9) and NN (N3000N\le3000)

In the second line of input you are given A_1,A_2,A_NA\_1,A\_2\cdots,A\_N, the initial positions of the marbles. All A_iA\_i are guaranteed to be distinct, and 1A_iL1\le A\_i\le L.

In the second line of input you are given B_1,B_2,B_NB\_1,B\_2\cdots,B\_N, the initial positions of the marbles. All B_iB\_i are guaranteed to be distinct, and 1B_iL1\le B\_i\le L.

출력

Print one integer: the minimum amount of time to have a marble on top of every switch. If solution does not exist, print 1-1.