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

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]
trans = steps.map {|s| mat ** s}

dist = { n => 0 }

loop do
    changed = false
    (1..n-1).each do |u|
        d = trans.map {|mat| (1..n).map {|v| mat[u, v] >= 1 ? (dist[v] || Float::INFINITY) : Float::INFINITY}.min}.max + 1
        next if d == Float::INFINITY
        if !dist[u] || d < dist[u]
            dist[u] = d
            changed = true
        end
    end
    break unless changed
end

puts dist[1] || 'IMPOSSIBLE'