extern crate core;

use std::fmt;
use std::cmp::{Ordering, min, max};
use std::f32::MAX;
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut, SubAssign, Range};
use std::collections::{BTreeMap, VecDeque, BinaryHeap, BTreeSet, HashMap};
use std::fmt::Display;

fn show<T: Display>(vec: &Vec<T>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        print!("[{}", vec[0]);
        for i in 1 .. vec.len() {
            print!(", {}", vec[i]);
        }
        println!("]");
    }
}
fn show2<T: Display>(vec: &Vec<Vec<T>>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        for l in vec {
            show(l);
        }
    }
}

macro_rules! read_line{
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).ok();
        line
    }};
    (delimiter: ' ') => {
        read_line!().split_whitespace().map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (delimiter: $p:expr) => {
        read_line!().split($p).map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (' ') => {
        read_line!(delimiter: ' ')
    };
    ($delimiter:expr) => {
        read_line!(delimiter: $delimiter)
    };
    (' '; $ty:ty) => {
        read_line!().split_whitespace().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
    ($delimiter:expr; $ty:ty) => {
        read_line!($delimiter).into_iter().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
}
macro_rules! read_value{
    () => {
        read_line!().trim().parse().ok().unwrap()
    }
}
macro_rules! let_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}

macro_rules! let_mut_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let mut $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
fn max_of(a: usize, b: usize, c: usize) -> usize {
    max(a, max(b, c))
}
fn main() {
    let_all!(n: usize, m: usize, a: usize, b: usize, c: usize);
    let mut nodes: Vec<Vec<usize>> = vec![Vec::new(); n];
    for _ in 0 .. m {
        let_all!(u: usize, v: usize);
        nodes[u - 1].push(v - 1)
    }
    let mut steps = vec![vec![Vec::new(); 3]; n];
    for i in 0 .. n {
        let mut step = vec![0; n];
        let mut deque = VecDeque::new(); deque.push_back(i);
        for s in 1 .. max_of(a, b, c) + 1 {
            for _ in 0 .. deque.len() {
                let current = deque.pop_front().unwrap();
                for &next in &nodes[current] {
                    if step[next] != s {
                        step[next] = s;
                        deque.push_back(next);
                    }
                }
            }
            if s == a {
                for j in 0 .. n {
                    if step[j] == s {
                        steps[j][0].push(i);
                    }
                }
            }
            if s == b {
                for j in 0 .. n {
                    if step[j] == s {
                        steps[j][1].push(i);
                    }
                }
            }
            if s == c {
                for j in 0 .. n {
                    if step[j] == s {
                        steps[j][2].push(i);
                    }
                }
            }
        }
    }
    let mut min_steps = vec![vec![-1_i32; 3]; n];
    min_steps[n - 1][0] = 0;
    min_steps[n - 1][1] = 0;
    min_steps[n - 1][2] = 0;
    let mut queue: VecDeque<(usize, usize)> = VecDeque::new();
    queue.push_back((n - 1, 0)); queue.push_back((n - 1, 1)); queue.push_back((n - 1, 2));
    while let Some((current, num)) = queue.pop_front() {
        if min_steps[current].iter().all(|&x|x >= 0) && min_steps[current].iter().max().unwrap() == &min_steps[current][num] {
            for step in 0..3 {
                for &next in &steps[current][step] {
                    if min_steps[next][step] == -1 {
                        min_steps[next][step] = min_steps[current][num] + 1;
                        queue.push_back((next, step));
                    }
                }
            }
        }
    }
    if min_steps[0].iter().all(|&x|x != -1) {
        println!("{}", min_steps[0].iter().max().unwrap());
    }else {
        println!("IMPOSSIBLE");
    }
}


Measured memory_bytes: 5052