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.*;
public class C { //no AC yet

	static long mod = 998244353;
	static int K = 20;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int m = sc.nextInt();
		ArrayList<Integer>[] g = new ArrayList[n];
		ArrayList<Integer>[] ginv = new ArrayList[n];
		for(int i = 0; i < n; i++){
			g[i] = new ArrayList<>();
			ginv[i] = new ArrayList<>();
		}
		for(int i = 0; i < m; i++){
			int u = sc.nextInt()-1;
			int v = sc.nextInt()-1;
			g[u].add(v);
			ginv[v].add(u);
		}
		PriorityQueue<Pair> q = new PriorityQueue<>();
		long[] dist = new long[K*n];
		Arrays.fill(dist, Long.MAX_VALUE);
		dist[0] = 0;
		Pair p2 = new Pair(0, 0);
		q.add(p2);
		while(!q.isEmpty()) {
			Pair p = q.poll();
			int k = p.u / n;
			int u = p.u % n;
			if(k % 2 == 0) {
				for(int v: g[u]) {
					long w = dist[p.u] + 1;
					int _v = k * n + v;
					if(dist[_v] > w) {
						dist[_v] = w; 
						p2 = new Pair(_v, w);
						q.add(p2);
					}
				}
			}
			else {
				for(int v: ginv[u]) {
					long w = dist[p.u] + 1;
					int _v = k * n + v;
					if(dist[_v] > w) {
						dist[_v] = w; 
						p2 = new Pair(_v, w);
						q.add(p2);
					}
				}
			}
			if(k < K-1) {
				int _v = p.u + n;
				long w = dist[p.u] + (1L << k);
				if(dist[_v] > w) {
					dist[_v] = w; 
					p2 = new Pair(_v, w);
					q.add(p2);
				}
			}
		}
		long res = Long.MAX_VALUE;
		for(int k = 0; k < K; k++){
			res = Math.min(res, dist[k*n+n-1]);
		}
		if(res < Long.MAX_VALUE) System.out.println(res % mod);
		else {
			long[] distn = new long[n];
			q = new PriorityQueue<>();
			for(int i = 0; i < n; i++){
				distn[i] = dist[(K-1)*n + i];
				if(distn[i] < Long.MAX_VALUE) q.add(new Pair(i, distn[i]));
			}
			long k = K;
			long pow = 1L << (K-1) % mod;
			long toadd = pow;
			PriorityQueue<Pair> newq = new PriorityQueue<>();
			while(!q.isEmpty()) {
				Pair p = q.poll();
				if(k % 2 == 0) {
					for(int v: g[p.u]) {
						long w = distn[p.u] + 1;
						if(w < distn[v]) {
							distn[v] = w;
							q.add(new Pair(v, w));
							newq.add(new Pair(v, w));
						}
					}
				}
				else {
					for(int v: ginv[p.u]) {
						long w = distn[p.u] + 1;
						if(w < distn[v]) {
							distn[v] = w;
							q.add(new Pair(v, w));
							newq.add(new Pair(v, w));
						}
					}
				}
				if(q.isEmpty()) {
					if(distn[n-1] < Long.MAX_VALUE) {
						System.out.println((distn[n-1] + toadd) % mod); return;
					}
					q = newq; newq = new PriorityQueue<Pair>(); k++; 
					pow = pow * 2 % mod; toadd = (toadd + pow) % mod;
				}
			}
			System.out.println("oof");
		}
	}
	static class Edge {
		int v; long w;
		public Edge(int v, long w) {
			this.v = v; this.w = w;
		}
		public String toString() {
			return v + " " + w;
		}
	}
	static class Pair implements Comparable<Pair>{
		int u; long w;
		public Pair(int u, long w) {
			this.u = u; this.w = w;
		}
		@Override
		public int compareTo(Pair p) {
			return Long.compare(w, p.w);
		}
		public String toString() {
			return u + " " + w;
		}
	}
	
	static class SegmentTree { //not used
		private int[] st; private int[] A;
		private int n;
		private int left (int p) { return p << 1; }
		private int right(int p) { return (p << 1) + 1; }
		
//		static int neutral = Integer.MAX_VALUE;					//MIN
//		static int op(int x, int y) { return Math.min(x, y); }
//		static int neutral = Integer.MIN_VALUE;					//MAX
//		static int op(int x, int y) { return Math.max(x, y); }
		static int neutral = 0;									//SUM
		static int op(int x, int y) { return x + y; }

		private void build(int p, int L, int R) {
			if (L == R)
				st[p] = A[L];
			else {
				build(left(p) , L              , (L + R) / 2);
				build(right(p), (L + R) / 2 + 1, R          );
				int v1 = st[left(p)], v2 = st[right(p)];
				st[p] = op(v1, v2);
			} }

		private int rmq(int p, int L, int R, int i, int j) {
			if (i >  R || j <  L) return neutral;
			if (L >= i && R <= j) return st[p];

			int v1 = rmq(left(p) , L              , (L+R) / 2, i, j);
			int v2 = rmq(right(p), (L+R) / 2 + 1, R          , i, j);

			return op(v1, v2);
		}

		private int update_point(int p, int L, int R, int idx, int new_value) {
			int i = idx, j = idx;
			if (i > R || j < L)
				return st[p];

			if (L == i && R == j) {
				A[i] = new_value;
				return st[p] = A[L];											// += IF DELTA
			}

			int v1, v2;
			v1 = update_point(left(p) , L              , (L + R) / 2, idx, new_value);
			v2 = update_point(right(p), (L + R) / 2 + 1, R          , idx, new_value);

			return st[p] = op(v1, v2);
		}

		public SegmentTree(int[] _A) {
			A = _A; n = A.length;
			st = new int[4 * n];
			for (int i = 0; i < 4 * n; i++) st[i] = 0;
			build(1, 0, n - 1);
		}

		public int rmq(int i, int j) { return rmq(1, 0, n - 1, i, j); }

		public int update_point(int idx, int new_value) {
			return update_point(1, 0, n - 1, idx, new_value); }
		
		public String toString() {
			return Arrays.toString(A);
		}
	}
	
	
	static class FastScanner {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		public FastScanner() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			tokenizer = null;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch(IOException e) {
				throw new RuntimeException(e);
			}
		}
	}

}