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 CF1442C{
  static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            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 nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        
    } 
    public static class Pair implements Comparable<Pair>{
        int vtx; long val;
        public Pair(int a, long b){
            this.vtx=a; this.val=b;
        }
        public int compareTo(Pair other){
            if(this.val<other.val)return -1;
            if(this.val>other.val)return 1;
            if(this.vtx<other.vtx)return -1;
            return 1;
        }
    }
    
    static int MOD=998244353;
    
    static int[] rk, p,siz;
    public static void main(String[] args){
        FastReader br=new FastReader();
        int N=br.nextInt(); int M=br.nextInt();
       
        ArrayList<Integer> adj[][]=new ArrayList[N][2];
        for (int i = 0; i < N; i++) {
            adj[i][0]=new ArrayList<>(); adj[i][1]=new ArrayList<>();
        }
        int a,b;
        for (int i = 0; i < M; i++) {
            a=br.nextInt()-1; b=br.nextInt()-1;
            adj[a][0].add(b); adj[b][1].add(a);
        }
        int log=0;
        for (int i = 17; i >=0; i--) {
            if((M&(1<<i))>0){
                log=i; break;
            }
        }
        int[][] dp=new int[N][log+2];
        
        for (int i = 0; i < N; i++) {
            Arrays.fill(dp[i],2*M);
        }
        dp[0][0]=0; Pair p; int v;
        for (int i = 0; i <= log; i++) {
            PriorityQueue<Long> pq=new PriorityQueue<>();
            for (int j = 0; j < N; j++) {
                if(dp[j][i]<=M){pq.add((long)dp[j][i]*MOD+j);}
            }
            boolean[] vis=new boolean[N];
            while(!pq.isEmpty()){
                v=(int) (pq.poll()%MOD); 
                if(vis[v])continue;
                vis[v]=true; //No need to visit a vertex twice
                //Having sorted everything by value, it is impossible for a visited vertex to optimize
                for (int j : adj[v][i%2]) {
                    if(dp[j][i]>dp[v][i]+1){
                        dp[j][i]=dp[v][i]+1;
                        pq.add((long)dp[j][i]*MOD+j);
                    }
                }
                for (int j : adj[v][1-i%2]) {
                    if(dp[j][i+1]>dp[v][i]+1){
                        dp[j][i+1]=dp[v][i]+1;
                        //pq.add((long)dp[j][i+1]*MOD+j);
                    }
                }
            }
        }
        int min=MOD;
        for (int i = 0; i <= log; i++) {
            if(dp[N-1][i]<=M){
                min=Math.min(min,dp[N-1][i]+(1<<i)-1);
            }
        }
        if(min<MOD){
            System.out.println(min);return;
        }
        
        int[][] dpL=new int[N][2];
        int[][] dpS=new int[N][2];
        //Always seek to minimize dpS then dpL
        for (int i = 1; i < N; i++) {
            dpL[i][0]=MOD; dpL[i][1]=MOD;
            dpS[i][0]=MOD;dpS[i][1]=MOD;
        }
        
        dpL[0][1]=MOD; dpS[0][1]=MOD;
        PriorityQueue<Pair> pq=new PriorityQueue<>();//M*dpS+dpL
        pq.add(new Pair(0,0));
        int l,s,x; boolean[][] vis=new boolean[N][2];
        while(!pq.isEmpty()){
            p=pq.poll(); v=p.vtx/2; x=p.vtx%2;
            
            if(!vis[v][x]){
                l=dpL[v][x]; s=dpS[v][x]; vis[v][x]=true;
                for (int i : adj[v][x]) {
                    if(dpS[i][x]>s){
                        dpS[i][x]=s; dpL[i][x]=l+1; pq.add(new Pair(2*i+x,(long)MOD*dpS[i][x]+dpL[i][x]));
                     }else if(dpS[i][x]==s && l+1<dpL[i][x]){
                         dpL[i][x]=l+1;pq.add(new Pair(2*i+x,(long)MOD*dpS[i][x]+dpL[i][x]));
                     }
                  }
                  for (int i : adj[v][1- x]) {
                        if(dpS[i][1-x]>s+1){
                            dpS[i][1-x]=s+1; dpL[i][1-x]=l+1; pq.add(new Pair(2*i+(1-x),(long)MOD*dpS[i][1-x]+dpL[i][1-x]));
                        }else if(dpS[i][1-x]==s+1 && l+1<dpL[i][1-x]){
                            dpL[i][1-x]=l+1;pq.add(new Pair(2*i+(1-x),(long)MOD*dpS[i][1-x]+dpL[i][1-x]));
                        }
                    }
                }    
            
        }
        if(dpS[N-1][0]<dpS[N-1][1]){
            System.out.println((pow(2,dpS[N-1][0])+dpL[N-1][0]-1)%MOD);
        }else if(dpS[N-1][0]>dpS[N-1][1]){
            System.out.println((pow(2,dpS[N-1][1])+dpL[N-1][1]-1)%MOD);
        }else if(dpL[N-1][0]<dpL[N-1][1]){
            System.out.println((pow(2,dpS[N-1][0])+dpL[N-1][0]-1)%MOD);
        }else{
            System.out.println((pow(2,dpS[N-1][1])+dpL[N-1][1]-1)%MOD);
        }
    }
    public static long pow(int b, long e){
        if(e==0)return 1; if(e==1)return b;
        long x=pow(b,e/2);
        return (x*x)%MOD*(pow(b,e%2))%MOD;
    }
    
    
}
//Debugging:
//Are you sure your algorithm is correct?
//Bounds: long
//Special cases: n=0,1?
//Make sure you remove your debugging code before you submit!