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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, P = 998244353;
int n, m, d[N][20], dis[N], vis[N][20];
vector<int> g[2][N];
queue<int> q1, q2;
int qpow(int b, int p) {
  int r = 1;
  for (; p; p >>= 1, b = 1LL * b * b % P)
    if (p & 1) r = 1LL * r * b % P;
  return r;
}
int Dijkstra() {
  priority_queue<pair<int, pair<int, int> >,
                 vector<pair<int, pair<int, int> > >,
                 greater<pair<int, pair<int, int> > > >
      q;
  memset(d, 0x3f, sizeof(d)), q.push({d[1][0] = 0, make_pair(1, 0)});
  while (!q.empty()) {
    pair<int, int> u = q.top().second;
    q.pop();
    if (vis[u.first][u.second]) continue;
    vis[u.first][u.second] = 1;
    if (u.first == n) return d[u.first][u.second];
    for (int v : g[u.second & 1][u.first])
      if (d[v][u.second] > d[u.first][u.second] + 1)
        q.push({d[v][u.second] = d[u.first][u.second] + 1,
                make_pair(v, u.second)});
    if (u.second < 18 &&
        d[u.first][u.second + 1] > d[u.first][u.second] + (1 << u.second))
      q.push({d[u.first][u.second + 1] = d[u.first][u.second] + (1 << u.second),
              make_pair(u.first, u.second + 1)});
  }
  return -1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, a, b; i <= m; ++i)
    scanf("%d%d", &a, &b), g[0][a].push_back(b), g[1][b].push_back(a);
  int res = Dijkstra();
  if (res != -1) return printf("%d", res), 0;
  q1.push(1), q2.push(1);
  memset(dis, 0x3f, sizeof(dis)), dis[1] = 0;
  for (int K = 0;; ++K) {
    while (!q1.empty()) {
      int u = q1.front();
      q1.pop();
      if (u == n) return printf("%d", (dis[u] + qpow(2, K) - 1) % P), 0;
      for (int v : g[K & 1][u])
        if (dis[v] > dis[u] + 1) dis[v] = dis[u] + 1, q1.push(v), q2.push(v);
    }
    while (!q2.empty()) q1.push(q2.front()), q2.pop();
  }
  return 0;
}