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.*;

public class Main {
	static LinkedList<int[]>[] adjListW;
	static int compare(int[]x,int[]y) {
		return x[1]==y[1]?x[0]-y[0]:x[1]-y[1];
	}
	static int[] dijkstra(int S, int T,int n)	//O(E log E)
	{
		
		int[][][] dist = new int[n][2][];
		int inf=(int)1e9;
		for(int i=0;i<n;i++) {
			for(int j=0;j<2;j++) {
				dist[i][j]=new int[] {inf,inf};
			}
		}
		PriorityQueue<int[]> pq = new PriorityQueue<int[]>((x,y)->compare(x, y));
		dist[S][0] = new int[] {0,0};
		pq.add(new int[] {S,0,0,0});
		while(!pq.isEmpty())
		{
			int[] cur = pq.poll();
			int node=cur[0],cost=cur[1],curK=cur[2],parity=cur[3];
			
			if(compare(new int[] {cost,curK}, dist[node][parity])>0)			//lazy deletion
				continue;
			for(int[]nxt: adjListW[node]) {
				if(nxt[1]==parity) {
					//no need to transposition
					if(compare(new int[] {cost+1,curK}, dist[nxt[0]][parity])<0) {
						dist[nxt[0]][parity] = new int[] {cost+1,curK};
						pq.add(new int[] {nxt[0],cost+1,curK,parity});
					}
				}
			}
			if(compare(new int[] {cost,curK+1}, dist[node][parity^1])<0) {
				dist[node][parity^1] = new int[] {cost,curK+1};
				pq.add(new int[] {node,cost,curK+1,parity^1});
			}
		}
		
		return compare(dist[T][0], dist[T][1])<0?dist[T][0]:dist[T][1];
	}
	static long dijkstra2(int S, int T,int n)	//O(E log E)
	{
		
		long[][] dist = new long[n][25];
		long inf=(long)1e16;
		for(int i=0;i<n;i++) {
			for(int j=0;j<25;j++) {
				dist[i][j]=inf;
			}
		}
		PriorityQueue<long[]> pq = new PriorityQueue<long[]>((x,y)->Long.compare(x[1], y[1]));
		dist[S][0] = 0;
		pq.add(new long[] {S,0,0});
		while(!pq.isEmpty())
		{
			long[] cur = pq.poll();
			int node=(int)cur[0];long cost=cur[1];int curK=(int)cur[2],parity=(int)(cur[2]&1);
			if(node==T) {
				return cost;
			}
			if(cost>dist[node][curK])			//lazy deletion
				continue;
			for(int[]nxt: adjListW[node]) {
				if(nxt[1]==parity) {
					//no need to transposition
					if(cost+1<dist[nxt[0]][curK]) {
						dist[nxt[0]][curK] = cost+1;
						pq.add(new long[] {nxt[0],cost+1,curK});
					}
				}
			}
			if(curK+1<25 && cost+(1<<curK)<dist[node][curK+1]) {
				dist[node][curK+1] = cost+(1<<curK);
				pq.add(new long[] {node,cost+(1<<curK),curK+1});
			}
		}
		
		return inf;
	}
	static void main() throws Exception {
		int n=sc.nextInt(),m=sc.nextInt();
		adjListW=new LinkedList[n];
		for(int i=0;i<n;i++)adjListW[i]=new LinkedList<int[]>();
		for(int i=0;i<m;i++) {
			int x=sc.nextInt()-1,y=sc.nextInt()-1;
			adjListW[x].add(new int[] {y,0});
			adjListW[y].add(new int[] {x,1});
		}
		long mod=998244353;
		long curAns=dijkstra2(0, n-1, n);
		if(curAns<=1e10) {
			pw.println(curAns%mod);
			return;
		}
		int[]ans=dijkstra(0, n-1, n);
		long finalAns=1;
		for(int i=0;i<ans[1];i++) {
			finalAns=(finalAns*2)%mod;
		}
		pw.println((finalAns+ans[0]-1+mod)%mod);
	}
	public static void main(String[] args) throws Exception {
		sc = new MScanner(System.in);
		pw = new PrintWriter(System.out);
		int tc = 1;
//		tc=sc.nextInt();
		for (int test = 1; test <= tc; test++) {
			main();
		}
		pw.flush();
	}

	static PrintWriter pw;
	static MScanner sc;

	static class MScanner {
		StringTokenizer st;
		BufferedReader br;

		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int[] intArr(int n) throws IOException {
			int[] in = new int[n];
			for (int i = 0; i < n; i++)
				in[i] = nextInt();
			return in;
		}

		public long[] longArr(int n) throws IOException {
			long[] in = new long[n];
			for (int i = 0; i < n; i++)
				in[i] = nextLong();
			return in;
		}

		public int[] intSortedArr(int n) throws IOException {
			int[] in = new int[n];
			for (int i = 0; i < n; i++)
				in[i] = nextInt();
			shuffle(in);
			Arrays.sort(in);
			return in;
		}

		public long[] longSortedArr(int n) throws IOException {
			long[] in = new long[n];
			for (int i = 0; i < n; i++)
				in[i] = nextLong();
			shuffle(in);
			Arrays.sort(in);
			return in;
		}

		public Integer[] IntegerArr(int n) throws IOException {
			Integer[] in = new Integer[n];
			for (int i = 0; i < n; i++)
				in[i] = nextInt();
			return in;
		}

		public Long[] LongArr(int n) throws IOException {
			Long[] in = new Long[n];
			for (int i = 0; i < n; i++)
				in[i] = nextLong();
			return in;
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}

	}

	static void shuffle(int[] in) {
		for (int i = 0; i < in.length; i++) {
			int idx = (int) (Math.random() * in.length);
			int tmp = in[i];
			in[i] = in[idx];
			in[idx] = tmp;
		}
	}

	static void shuffle(long[] in) {
		for (int i = 0; i < in.length; i++) {
			int idx = (int) (Math.random() * in.length);
			long tmp = in[i];
			in[i] = in[idx];
			in[idx] = tmp;
		}
	}
}