import java.util.*; import java.io.*; class Main{ private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); private static final PrintWriter out = new PrintWriter(System.out); public static void main(String[] args)throws IOException{ String[] str = br.readLine().split(" "); int N = Integer.parseInt(str[0]); int M = Integer.parseInt(str[1]); ArrayList> list = new ArrayList<>(); for(int i=0;i<=N;i++) list.add(new ArrayList<>()); while(M-->0){ str = br.readLine().split(" "); int u = Integer.parseInt(str[0]); int v = Integer.parseInt(str[1]); list.get(u).add(v); } PriorityQueue queue = new PriorityQueue<>((a,b)->Integer.compare(a[1],b[1])); int[] dist = new int[4*N+1]; Arrays.fill(dist,Integer.MAX_VALUE); dist[1] = 0; queue.add(new int[]{1,0,0}); while(queue.size()>0){ int[] now = queue.poll(); if(dist[now[0]+now[2]*N]