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:
//stan hu tao
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.util.*;
import java.io.*;
import java.math.*;

public class x1442C
{
    static final long MOD = 998244353L;
    static final int INF = (Integer.MAX_VALUE-69)/2;
    static int[][] edges;
    static int[][] transpose;
    public static void main(String hi[]) throws Exception
    {
        FastScanner infile = new FastScanner();
        int N = infile.nextInt();
        int M = infile.nextInt();
        int[] ec = new int[N];
        int[] tc = new int[N];
        ArrayDeque<Integer> input = new ArrayDeque<Integer>();
        while(M-->0)
        {
            int a = infile.nextInt()-1;
            int b = infile.nextInt()-1;
            input.add(a); input.add(b);
            ec[a]++; tc[b]++;
        }
        edges = new int[N][];
        transpose = new int[N][];
        for(int i=0; i < N; i++)
        {
            edges[i] = new int[ec[i]];
            transpose[i] = new int[tc[i]];
        }
        while(input.size() > 0)
        {
            int a = input.poll();
            int b = input.poll();
            edges[a][--ec[a]] = b;
            transpose[b][--tc[b]] = a;
        }
        int[][] dist = new int[N][20];
        for(int i=0; i < N; i++)
            Arrays.fill(dist[i], INF);
        boolean[][] seen = new boolean[N][20];
        dist[0][0] = 0;
        PriorityQueue<Node> pq1 = new PriorityQueue<Node>((x,y) -> {
            return Integer.compare(x.dist, y.dist);
        });
        pq1.add(new Node(0, 0, 0));
        while(pq1.size() > 0)
        {
            Node curr = pq1.poll();
            if(seen[curr.id][curr.b])
                continue;
            seen[curr.id][curr.b] = true;
            int[] ls = edges[curr.id];
            if((curr.b&1) == 1)
                ls = transpose[curr.id];
            for(int next: ls)
                if(dist[next][curr.b] > dist[curr.id][curr.b]+1)
                {
                    dist[next][curr.b] = dist[curr.id][curr.b]+1;
                    pq1.add(new Node(next, curr.b, dist[next][curr.b]));
                }
            if(curr.b < 19 && dist[curr.id][curr.b+1] > dist[curr.id][curr.b]+(1<<curr.b))
            {
                dist[curr.id][curr.b+1] = dist[curr.id][curr.b]+(1<<curr.b);
                pq1.add(new Node(curr.id, curr.b+1, dist[curr.id][curr.b+1]));
            }
        }
        long res = INF;
        for(int b=0; b < 20; b++)
            res = min(res, dist[N-1][b]);
        if(res < INF)
        {
            System.out.println(res%MOD);
            return;
        }
        PriorityQueue<Node> pq = new PriorityQueue<Node>((x,y) -> {
            return x.compareTo(y);
        });
        dist = new int[N][2];
        int[][] coeff = new int[N][2]; //power of 2
        for(int i=0; i < N; i++)
            coeff[i][0] = coeff[i][1] = 500000;
        pq.add(new Node(0, 0, 0));
        coeff[0][0] = 0;
        seen = new boolean[N][2];
        while(pq.size() > 0)
        {
            Node curr = pq.poll();
            int tag = curr.b&1;
            if(curr.id == N-1)
            {
                res = 1L;
                while(coeff[curr.id][tag]-->0)
                    res = (res*2)%MOD;
                res = (res-1+MOD)%MOD;
                res = (res+dist[curr.id][tag])%MOD;
                System.out.println(res);
                return;
            }
            if(seen[curr.id][tag])
                continue;
            seen[curr.id][tag] = true;
            int[] ls = edges[curr.id];
            if(tag == 1)
                ls = transpose[curr.id];
            for(int next: ls)
                if(check(coeff[next][tag], dist[next][tag], curr.b, curr.dist+1) > 0)
                {
                    coeff[next][tag] = curr.b;
                    dist[next][tag] = curr.dist+1;
                    pq.add(new Node(next, curr.b, curr.dist+1));
                }
            if(check(coeff[curr.id][(tag)^1], dist[curr.id][(tag)^1], curr.b+1, curr.dist) > 0)
            {
                coeff[curr.id][(tag)^1] = curr.b+1;
                dist[curr.id][(tag)^1] = curr.dist;
                pq.add(new Node(curr.id, curr.b+1, curr.dist));
            }
        }
    }
    public static int check(int b1, int d1, int b2, int d2)
    {
        //if(max(b1, b2) <= 20)
        //    return Long.compare((1<<b1)-1+d1, (1<<b2)-1+d2);
        if(b1 != b2)
            return b1-b2;
        return Integer.compare(d1, d2);
    }
}
class Node
{
    public int id;
    public int b;
    public int dist;

    public Node(int a, int bb, int d)
    {
        id = a;
        b = bb;
        dist = d;
    }
    public int compareTo(Node oth)
    {
        int b1 = b;   int b2 = oth.b;
        //if(max(b1, b2) <= 20)
        //    return Long.compare((1<<b1)-1+dist, (1<<b2)-1+oth.dist);
        if(b1 != b2)
            return b1-b2;
        return Integer.compare(dist, oth.dist);
    }
}
class FastScanner
{
    private int BS = 1 << 16;
    private char NC = (char) 0;
    private byte[] buf = new byte[BS];
    private int bId = 0, size = 0;
    private char c = NC;
    private double cnt = 1;
    private BufferedInputStream in;

    public FastScanner() {
        in = new BufferedInputStream(System.in, BS);
    }

    public FastScanner(String s) {
        try {
            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
        } catch (Exception e) {
            in = new BufferedInputStream(System.in, BS);
        }
    }

    private char getChar() {
        while (bId == size) {
            try {
                size = in.read(buf);
            } catch (Exception e) {
                return NC;
            }
            if (size == -1) return NC;
            bId = 0;
        }
        return (char) buf[bId++];
    }

    public int nextInt() {
        return (int) nextLong();
    }

    public int[] nextInts(int N) {
        int[] res = new int[N];
        for (int i = 0; i < N; i++) {
            res[i] = (int) nextLong();
        }
        return res;
    }

    public long[] nextLongs(int N) {
        long[] res = new long[N];
        for (int i = 0; i < N; i++) {
            res[i] = nextLong();
        }
        return res;
    }

    public long nextLong() {
        cnt = 1;
        boolean neg = false;
        if (c == NC) c = getChar();
        for (; (c < '0' || c > '9'); c = getChar()) {
            if (c == '-') neg = true;
        }
        long res = 0;
        for (; c >= '0' && c <= '9'; c = getChar()) {
            res = (res << 3) + (res << 1) + c - '0';
            cnt *= 10;
        }
        return neg ? -res : res;
    }

    public double nextDouble() {
        double cur = nextLong();
        return c != '.' ? cur : cur + nextLong() / cnt;
    }

    public double[] nextDoubles(int N) {
        double[] res = new double[N];
        for (int i = 0; i < N; i++) {
            res[i] = nextDouble();
        }
        return res;
    }

    public String next() {
        StringBuilder res = new StringBuilder();
        while (c <= 32) c = getChar();
        while (c > 32) {
            res.append(c);
            c = getChar();
        }
        return res.toString();
    }

    public String nextLine() {
        StringBuilder res = new StringBuilder();
        while (c <= 32) c = getChar();
        while (c != '\n') {
            res.append(c);
            c = getChar();
        }
        return res.toString();
    }

    public boolean hasNext() {
        if (c > 32) return true;
        while (true) {
            c = getChar();
            if (c == NC) return false;
            else if (c > 32) return true;
        }
    }
}