require 'matrix'
n, m, *steps = gets.split.map(&:to_i)

reachable = [nil]
mat = (0..n).map { (0..n).map { 0 } }
m.times do
    i, j = gets.split.map(&:to_i)
    mat[i][j] = 1
end
mat = Matrix[*mat]
reachable << mat

steps.max.times do
    reachable << reachable[1] * reachable[-1]
end

trans = steps.map {|i| reachable[i]}

require 'set'
visited = Set.new

def min_max(u, g, visited, trans)
    return Float::INFINITY if visited.include?(u)
    return visited.size if u == g
    s = visited.dup
    s << u
    trans.map {|mat|
        (1..mat.row_size-1).map {|v|
            mat[u, v] == 0 ? Float::INFINITY : min_max(v, g, s, trans)
        }.min
    }.max
end

d = min_max(1, n, Set.new, trans)
puts d == Float::INFINITY ? 'IMPOSSIBLE' : d