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.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    static PrintWriter out;
    static Reader in;
    public static void main(String[] args) throws IOException {
        //in = new Reader(new FileInputStream(args[0])); // test.
        input_output();
        Main solver = new Main();
        solver.solve();
        out.close(); // remove test.
        out.flush(); // remove test.
    }
 
    static int INF = (int)1e9;
    static int maxn = (int)2e5+5;
    static int mod = 998244353;
    static int n, m, q, t, k;

    static List<Edge> adj[][];

    void solve() throws IOException{
    	n = in.nextInt();
    	m = in.nextInt();

    	adj = new ArrayList[n+1][2];
    	for (int i = 1; i <= n; i++)
    		for (int j = 0; j < 2; j++) 
    			adj[i][j] = new ArrayList<Edge>();

    	int[] x = new int[m],
    		  y = new int[m];
    	for (int i = 0; i < m; i++) {
    		int u = in.nextInt(),
    			v = in.nextInt();
    		x[i] = u;
    		y[i] = v;
			adj[u][0].add(new Edge(1, v, 0));
			adj[v][1].add(new Edge(1, u, 1));
    	}

    	for (int i = 1; i <= n; i++) {
    		for (int j = 0; j <= 1; j++) {
    			adj[i][j].add(new Edge(0, i, j^1));
    		}
    	}

    	int[][] dist = new int[n+1][18];
    	for (int i = 1; i <= n; i++)
    		for (int j = 0; j < 18; j++)
    			dist[i][j] = INF;

    	ShortPath(1, dist);

    	long[] pow = new long[maxn];
    	pow[0] = 1;
    	for (int i = 1; i < maxn; i++) pow[i] = (pow[i-1]*2)%mod;
    	for (int i = 0; i < maxn; i++) pow[i] = (pow[i]-1+mod)%mod;

    	long ans = mod;
    	for (int i = 0; i <= 17; i++) {
    		if (dist[n][i] != INF) {
    			if (ans == mod) ans = dist[n][i]+pow[i];
    			else ans = Math.min(ans, dist[n][i]+pow[i]);
    		}
    	}

    	if (ans != mod) {
    		out.println(ans);
    		return;
		}

		boolean[][] vis = new boolean[n+5][2];
		for (int i = 1; i <= n; i++) {
			dist[i][0] = INF;
			dist[i][1] = INF;
		}

		PriorityQueue<Edge> cur = new PriorityQueue<>();
		PriorityQueue<Edge> next = new PriorityQueue<>();
		int cnt = 0, anslvl = INF;
		cur.add(new Edge(0, 1, 0));
		dist[1][0] = 0;
		while (!vis[n][0] || !vis[n][1]) {
			if (cur.size() == 0) break;
			while (cur.size() != 0) {
				Edge edge = cur.remove();
				vis[edge.to][edge.lvl] = true;

				if (edge.weight > dist[edge.to][edge.lvl]) continue;

	            for(Edge e:adj[edge.to][edge.lvl]){

	            	if (e.to == n) {
	            		anslvl = Math.min(anslvl, cnt+(e.weight^1));
	            	}
	                if(dist[edge.to][edge.lvl]+e.weight<dist[e.to][e.lvl]){
	                	if (e.to == n && cnt+(e.weight^1) > anslvl) continue;
	                    dist[e.to][e.lvl] = dist[edge.to][edge.lvl]+e.weight;
	                    if (e.lvl == edge.lvl) cur.add(new Edge(dist[e.to][e.lvl], e.to, e.lvl));
	                    else next.add(new Edge(dist[e.to][e.lvl], e.to, e.lvl));
	                }
	            }
			}

			cnt++;
			while (next.size() != 0) {
				cur.add(next.remove());
			}
		}

		ans = (pow[anslvl]+Math.min(dist[n][0], dist[n][1]))%mod;
		out.println(ans);
    }

    //<>

    static void ShortPath(int s,int[][] dist){
    	ArrayDeque<Edge> q = new ArrayDeque<>();
	    //PriorityQueue<Edge> q = new PriorityQueue<Edge>();
	    dist[s][0] = 0;
	    q.add(new Edge(0, s, 0));

	    while(q.size()>0){
			Edge edge = q.removeFirst();
			int element = edge.to;
			if (edge.weight > dist[edge.to][edge.lvl]) continue;

            for(Edge e:adj[element][edge.lvl%2]){
            	if (edge.lvl+(e.weight^1) > 17) continue;
                if(dist[element][edge.lvl]+e.weight<dist[e.to][edge.lvl+(e.weight == 0 ? 1:0)]){
                    dist[e.to][edge.lvl+(e.weight == 0?1:0)] = dist[element][edge.lvl]+e.weight;
                    if (e.weight == 0) q.addFirst(new Edge(dist[e.to][edge.lvl+1], e.to, edge.lvl+1));
                    else q.addLast(new Edge(dist[e.to][edge.lvl], e.to, edge.lvl));
                }
            }
        }
    }

    static class Edge implements Comparable<Edge>{
    	int weight, to, lvl;

    	Edge(int weight, int to, int lvl) {
    		this.weight = weight;
    		this.to = to;
    		this.lvl = lvl;
    	}

    	public int compareTo(Edge o) {
    		return this.weight - o.weight;
    	}
    }

    static class Reader {
 
        private InputStream mIs;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
    
        public Reader() {
            this(System.in);
        }
    
        public Reader(InputStream is) {
            mIs = is;
        }
    
        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
    
        }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = mIs.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }
    
        public String nextLine() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }
    
        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }
    
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
    
        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
    
        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
    
        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
    
        public boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }
 
    }
    static void input_output() throws IOException {
        File f = new File("in.txt");
        if(f.exists() && !f.isDirectory()) { 
            in = new Reader(new FileInputStream("in.txt"));
        } else in = new Reader();
        f = new File("out.txt");
        if(f.exists() && !f.isDirectory()) {
            out = new PrintWriter(new File("out.txt"));
        } else out = new PrintWriter(System.out);
    }
}