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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.stream.IntStream;
import java.util.TreeSet;
import java.util.ArrayList;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.List;
import java.util.stream.Stream;
import java.io.Closeable;
import java.io.Writer;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            CGraphTranspositions solver = new CGraphTranspositions();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class CGraphTranspositions {
        long inf = (long) 1e18;
        List<DirectedEdge>[] g;
        List<DirectedEdge>[] revg;

        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            int m = in.readInt();

            int threshold = 20;

            g = Graph.createGraph(n);
            revg = Graph.createGraph(n);
            for (int i = 0; i < m; i++) {
                int u = in.readInt() - 1;
                int v = in.readInt() - 1;

                Graph.addEdge(g, u, v);
                Graph.addEdge(revg, v, u);
            }

            Node[][] nodes = new Node[threshold][n];
            for (int i = 0; i < threshold; i++) {
                for (int j = 0; j < n; j++) {
                    nodes[i][j] = new Node();
                    nodes[i][j].id = j * 100 + i;
                    nodes[i][j].dist = inf;
                }
            }

            TreeSet<Node> set = new TreeSet<>((a, b) -> a.dist == b.dist ? Integer.compare(a.id, b.id) : Long.compare(a.dist, b.dist));
            nodes[0][0].dist = 0;
            set.add(nodes[0][0]);
            while (!set.isEmpty()) {
                Node head = set.pollFirst();
                int v = vertex(head.id);
                int b = time(head.id);

                if (b + 1 < threshold) {
                    long cand = head.dist + (1 << b);
                    if (nodes[b + 1][v].dist > cand) {
                        set.remove(nodes[b + 1][v]);
                        nodes[b + 1][v].dist = cand;
                        set.add(nodes[b + 1][v]);
                    }
                }

                List<DirectedEdge>[] cur = b % 2 == 0 ? g : revg;
                for (DirectedEdge e : cur[v]) {
                    long cand = head.dist + 1;
                    if (nodes[b][e.to].dist > cand) {
                        set.remove(nodes[b][e.to]);
                        nodes[b][e.to].dist = cand;
                        set.add(nodes[b][e.to]);
                    }
                }
            }

            long min = inf;
            for (int i = 0; i < threshold; i++) {
                min = Math.min(min, nodes[i][n - 1].dist);
            }

            if (min < inf) {
                out.println(min);
                return;
            }

            Comparator<Vertex> comparator = (a, b) -> {
                int comp = Integer.compare(a.jump, b.jump);
                if (comp == 0) {
                    comp = Long.compare(a.dist, b.dist);
                }
                if (comp == 0) {
                    comp = Integer.compare(a.id, b.id);
                }
                return comp;
            };
            TreeSet<Vertex> pq = new TreeSet<>(comparator);
            Vertex[][] vs = new Vertex[2][n];
            for (int k = 0; k < 2; k++) {
                for (int i = 0; i < n; i++) {
                    vs[k][i] = new Vertex();
                    vs[k][i].id = i;
                    vs[k][i].jump = (int) 1e9 - k;
                    vs[k][i].dist = inf;

                    if (k == ((threshold - 1) & 1)) {
                        if (nodes[threshold - 1][i].dist == inf) {
                            vs[k][i].dist = inf;
                            vs[k][i].jump = (int) 1e9 - k;
                        } else {
                            vs[k][i].dist = nodes[threshold - 1][i].dist - ((1 << (threshold - 1)) - 1);
                            vs[k][i].jump = threshold - 1;
                            pq.add(vs[k][i]);
                        }
                    }
                }
            }

            while (!pq.isEmpty()) {
                Vertex head = pq.pollFirst();
                List<DirectedEdge>[] cur = head.jump % 2 == 0 ? g : revg;

                Vertex opposite = vs[(head.jump & 1) ^ 1][head.id];
                if (opposite.jump > head.jump + 1 || opposite.jump == head.jump + 1 && opposite.dist > head.dist) {
                    pq.remove(opposite);
                    opposite.jump = head.jump + 1;
                    opposite.dist = head.dist;
                    pq.add(opposite);
                }

                for (DirectedEdge e : cur[head.id]) {
                    Vertex v = vs[head.jump & 1][e.to];
                    if (v.jump > head.jump || v.jump == head.jump && v.dist > head.dist + 1) {
                        pq.remove(v);
                        v.jump = head.jump;
                        v.dist = head.dist + 1;
                        pq.add(v);
                    }
                }
            }

            Vertex ans = CompareUtils.min(vs[0][n - 1], vs[1][n - 1], comparator);

            int mod = 998244353;
            Power pow = new Power(mod);
            long sum = ans.dist + pow.pow(2, ans.jump) - 1;
            sum = DigitUtils.mod(sum, mod);
            out.println(sum);
        }

        public int time(int x) {
            return x % 100;
        }

        public int vertex(int x) {
            return x / 100;
        }

    }

    static class Modular {
        int m;

        public int getMod() {
            return m;
        }

        public Modular(int m) {
            this.m = m;
        }

        public Modular(long m) {
            this.m = (int) m;
            if (this.m != m) {
                throw new IllegalArgumentException();
            }
        }

        public Modular(double m) {
            this.m = (int) m;
            if (this.m != m) {
                throw new IllegalArgumentException();
            }
        }

        public String toString() {
            return "mod " + m;
        }

    }

    static interface InverseNumber {
    }

    static class DirectedEdge {
        public int to;

        public DirectedEdge(int to) {
            this.to = to;
        }

        public String toString() {
            return "->" + to;
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private static final int THRESHOLD = 1 << 13;
        private final Writer os;
        private StringBuilder cache = new StringBuilder(THRESHOLD * 2);

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        private void afterWrite() {
            if (cache.length() < THRESHOLD) {
                return;
            }
            flush();
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            afterWrite();
            return this;
        }

        public FastOutput append(long c) {
            cache.append(c);
            afterWrite();
            return this;
        }

        public FastOutput append(String c) {
            cache.append(c);
            afterWrite();
            return this;
        }

        public FastOutput println(long c) {
            return append(c).println();
        }

        public FastOutput println() {
            return append(System.lineSeparator());
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class CompareUtils {
        private CompareUtils() {
        }

        public static <T> T min(T a, T b, Comparator<T> comp) {
            return comp.compare(a, b) <= 0 ? a : b;
        }

    }

    static class Power implements InverseNumber {
        int mod;

        public Power(Modular modular) {
            this.mod = modular.getMod();
        }

        public Power(int mod) {
            this(new Modular(mod));
        }

        public int pow(int x, int n) {
            if (n == 0) {
                return 1 % mod;
            }
            long r = pow(x, n >> 1);
            r = r * r % mod;
            if ((n & 1) == 1) {
                r = r * x % mod;
            }
            return (int) r;
        }

    }

    static class Graph {
        public static void addEdge(List<DirectedEdge>[] g, int s, int t) {
            g[s].add(new DirectedEdge(t));
        }

        public static List[] createGraph(int n) {
            return IntStream.range(0, n).mapToObj(i -> new ArrayList<>()).toArray(i -> new List[i]);
        }

    }

    static class DigitUtils {
        private DigitUtils() {
        }

        public static int mod(long x, int mod) {
            if (x < -mod || x >= mod) {
                x %= mod;
            }
            if (x < 0) {
                x += mod;
            }
            return (int) x;
        }

    }

    static class Node {
        long dist;
        int id;

    }

    static class Vertex {
        long dist;
        int jump;
        int id;

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }
}