Problem: You are given a directed graph of n vertices and m edges. Vertices are numbered from 1 to n. There is a token in vertex 1.

The following actions are allowed: 

  * Token movement. To move the token from vertex u to vertex v if there is an edge u → v in the graph. This action takes 1 second. 
  * Graph transposition. To transpose all the edges in the graph: replace each edge u → v by an edge v → u. This action takes increasingly more time: k-th transposition takes 2^{k-1} seconds, i.e. the first transposition takes 1 second, the second one takes 2 seconds, the third one takes 4 seconds, and so on. 



The goal is to move the token from vertex 1 to vertex n in the shortest possible time. Print this time modulo 998 244 353.

Input

The first line of input contains two integers n, m (1 ≤ n, m ≤ 200 000).

The next m lines contain two integers each: u, v (1 ≤ u, v ≤ n; u ≠ v), which represent the edges of the graph. It is guaranteed that all ordered pairs (u, v) are distinct.

It is guaranteed that it is possible to move the token from vertex 1 to vertex n using the actions above.

Output

Print one integer: the minimum required time modulo 998 244 353.

Examples

Input


4 4
1 2
2 3
3 4
4 1


Output


2


Input


4 3
2 1
2 3
4 3


Output


10

Note

The first example can be solved by transposing the graph and moving the token to vertex 4, taking 2 seconds.

The best way to solve the second example is the following: transpose the graph, move the token to vertex 2, transpose the graph again, move the token to vertex 3, transpose the graph once more and move the token to vertex 4.

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;
import java.math.*;
 
 
//Sub_To_Errichto
public class Main {
    //static final long MOD = 1000000007L;
    //static final long MOD2 = 1000000009L;
    static final long MOD = 998244353L;
    static final int INF = 50000000;
    static final int NINF = -500000000;
    
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);
        
        int N = sc.ni();
        int M = sc.ni();
        ArrayList<Integer>[] graph = new ArrayList[N];
        ArrayList<Integer>[] transpose = new ArrayList[N];
        for (int i = 0; i < N; i++) {
        	graph[i] = new ArrayList<Integer>();
        	transpose[i] = new ArrayList<Integer>();
        }
        
        Dijkstra dij = new Dijkstra(2*N);
        for (int i = 0; i < M; i++) {
        	int u = sc.ni()-1;
        	int v = sc.ni()-1;
        	graph[u].add(v);
        	transpose[v].add(u);
        	dij.addEdge(u, v, 1);
        	dij.addEdge(v, N+u,1000000);
        	dij.addEdge(N+v, N+u,1);
        	dij.addEdge(N+u, v, 1000000);
        }
        
        ArrayDeque<Integer> bfs = new ArrayDeque<Integer>();
        int[] dist = new int[18*N];
        Arrays.fill(dist, INF);
        dist[0] = 0;
        bfs.add(0);
        while (!bfs.isEmpty()) {
        	int val = bfs.pollFirst();
        	int t = val/N;
        	int n = val%N;
        	if ((t&1) == 0) {
        		for (int next: graph[n]) {
        			if (dist[next+t*N]==INF) {
        				dist[next+t*N] = dist[val]+1;
        				bfs.add(next+t*N);
        			}
        		}
        		for (int next: transpose[n]) {
        			if (t < 17 && dist[next+(t+1)*N]==INF) {
        				dist[next+(t+1)*N] = dist[val]+1;
        				bfs.add(next+(t+1)*N);
        			}
        		}
        	} else {
        		for (int next: transpose[n]) {
        			if (dist[next+t*N]==INF) {
        				dist[next+t*N] = dist[val]+1;
        				bfs.add(next+t*N);
        			}
        		}
        		for (int next: graph[n]) {
        			if (t < 17 && dist[next+(t+1)*N]==INF) {
        				dist[next+(t+1)*N] = dist[val]+1;
        				bfs.add(next+(t+1)*N);
        			}
        		}
        	}
        }
        int ans = INF;
        for (int i = 0; i < 18; i++) {
        	int j = i*N+(N-1);
        	ans = Math.min(ans, dist[j]+(1<<i)-1);
        }
        if (ans < INF) {
        	pw.println(ans);
        	pw.close();
        	return;
        }
        long[] travel = dij.dijkstra(0);
        long val = Math.min(travel[N-1],travel[2*N-1]);
        long tranposes = val/1000000;
        long walks = val%1000000;
        long finalAns = (power(2,tranposes,MOD)-1+tranposes+walks)%MOD;
        pw.println(finalAns);
        pw.close();
    }
    
    //Fast exponentiation (x^y mod m)
    public static long power(long x, long y, long m) {
    	long ans = 1;
    	x %= m;
    	while (y > 0) {
    		if((y&1)==1)
    			ans = (ans * x) % m;
    		y /= 2;
    		x = (x * x) % m;
    	}
    	return ans;
    }
    
    static class Dijkstra {
    	public int N;
    	public ArrayList<long[]>[] graph;

    	public Dijkstra(int numNodes) {
    		N = numNodes;
    		graph = new ArrayList[N];
    		for (int i = 0; i < N; i++) {
    			graph[i] = new ArrayList<long[]>();
    		}
    	}

    	//uncomment the last line to make every edge two-way
    	public void addEdge(long[] edge) {
    		graph[(int)edge[0]].add(new long[]{edge[1],edge[2]});
    		//graph[(int)edge[1]].add(new long[]{edge[0],edge[2]});
    	}

    	public void addEdge(int n1, int n2, long w) {
    		graph[n1].add(new long[]{n2,w});
    		//graph[n2].add(new long[]{n1,w});
    	}

    	//uncomment the lines with "previousNode" if you'd like to calculate that
    	public long[] dijkstra(int root) {
    		//long[] previousNode = new long[N];
    		//Arrays.fill(previousNode,-1);

    		long[] distances = new long[N];
    		Arrays.fill(distances,Long.MAX_VALUE);
    		distances[root] = 0L;

    		PriorityQueue<long[]> pq = new PriorityQueue<long[]>(new Comparator<long[]>() {
    			@Override
    			public int compare(long[] arr1, long[] arr2) {
    				if (arr1[1] < arr2[1])
    					return -1;
    				else if (arr1[1] > arr2[1])
    					return 1;
    				else
    					return 0;
    			}
    		});
    		long[] temp = new long[]{root,0};
    		pq.add(temp);
    		while (! pq.isEmpty()) {
    			temp = pq.poll();
    			for (long[] e: graph[(int)temp[0]]) {
    				int child = (int)e[0];
    				long w = e[1];
    				int node = (int)temp[0];
    				if (distances[child] > distances[node] + w) {
    					//previousNode[child] = temp.node;
    					distances[child] = distances[node] + w;
    					pq.add(new long[]{child,distances[child]});
    				}
    			}
    		}

    		return distances;
    	}
    }
    
    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
 
        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int ni() {
            return Integer.parseInt(next());
        }
 
        long nl() {
            return Long.parseLong(next());
        }
 
        double nd() {
            return Double.parseDouble(next());
        }
 
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}