#K12681. Minimum Waiting Time for a Favorable Train Station

    ID: 23745 Type: Default 1000ms 256MiB

Minimum Waiting Time for a Favorable Train Station

Minimum Waiting Time for a Favorable Train Station

Brad is catching a train and boards at the first station. Given the arrival times at each station and a list of his favorite (favorable) stations, your task is to compute the minimum waiting time that he has to endure to reach one of these favorable stations.

Formally, let \(a_1, a_2, \ldots, a_n\) denote the arrival times at the stations. If \(F\) is the set of favorable station indices (1-indexed), then the waiting time for a station \(i \in F\) is \(a_i - a_1\). You are required to find \(\min_{i \in F}(a_i - a_1)\).

inputFormat

The input is read from standard input (stdin) and contains three lines:

  • The first line contains two integers \(n\) and \(m\) --- the number of stations and the number of favorable stations, respectively.
  • The second line contains \(n\) integers \(a_1, a_2, \ldots, a_n\) representing the arrival times at each station.
  • The third line contains \(m\) distinct integers specifying the indices (1-indexed) of the favorable stations.

outputFormat

Output a single integer, which is the minimum waiting time for Brad to reach one of his favorable stations. This integer should be written to standard output (stdout).

## sample
5 2
1 3 5 7 9
2 4
2