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;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  char c = getchar();
  long long su = 0, f = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) su = su * 10 + c - '0';
  return su * f;
}
inline void write(long long x) {
  if (x < 0) {
    putchar('-');
    write(-x);
    return;
  }
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writesp(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  write(a);
  putchar(' ');
}
inline void writeln(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  write(a);
  puts("");
}
long long quickPower(long long x, long long y) {
  long long ans = 1;
  x %= 998244353;
  while (y > 0) {
    if (y & 1) (ans *= x) %= 998244353;
    (x *= x) %= 998244353;
    y >>= 1;
  }
  return ans;
}
long long n, m, dis[19][400005], dis1[400005], u, v, ans, vis[400005];
vector<long long> G[400005][2];
vector<pair<long long, long long> > G1[400005];
struct wcr {
  long long x, y;
  bool operator<(const wcr &A) const { return dis[x][y] > dis[A.x][A.y]; }
};
priority_queue<wcr> q;
priority_queue<pair<long long, long long> > q1;
wcr now;
pair<long long, long long> now1;
signed main() {
  n = read(), m = read();
  for (long long i = (0); i <= (18); i++)
    for (long long j = (1); j <= (n); j++) dis[i][j] = (1e18);
  for (long long i = (1); i <= (n); i++)
    G1[i].push_back(make_pair(i + n, 10000000)),
        G1[i + n].push_back(make_pair(i, 10000000));
  for (long long i = (1); i <= (m); i++) {
    u = read(), v = read();
    G[u][0].push_back(v);
    G[v][1].push_back(u);
    G1[u].push_back(make_pair(v, 1));
    G1[v + n].push_back(make_pair(u + n, 1));
  }
  q.push({0, 1});
  dis[0][1] = 0;
  while (!q.empty()) {
    now = q.top();
    q.pop();
    if (now.x <= 17) {
      if (dis[now.x + 1][now.y] > dis[now.x][now.y] + (1ll << now.x)) {
        dis[now.x + 1][now.y] = dis[now.x][now.y] + (1ll << now.x);
        q.push({now.x + 1, now.y});
      }
    }
    for (long long i = (0); i < (G[now.y][now.x % 2].size()); i++) {
      if (dis[now.x][G[now.y][now.x % 2][i]] > dis[now.x][now.y] + 1) {
        dis[now.x][G[now.y][now.x % 2][i]] = dis[now.x][now.y] + 1;
        q.push({now.x, G[now.y][now.x % 2][i]});
      }
    }
  }
  ans = (1e18);
  for (long long i = (0); i <= (18); i++) ans = min(ans, dis[i][n]);
  if (ans != (1e18))
    writeln(ans % 998244353);
  else {
    for (long long i = (1); i <= (2 * n + 5); i++) dis1[i] = (1e18);
    dis1[1] = 0;
    q1.push(make_pair(0, 1));
    while (!q1.empty()) {
      now1 = q1.top();
      q1.pop();
      if (vis[now1.second]) continue;
      vis[now1.second] = 1;
      for (long long i = (0); i < (G1[now1.second].size()); i++) {
        if (dis1[G1[now1.second][i].first] >
            dis1[now1.second] + G1[now1.second][i].second) {
          dis1[G1[now1.second][i].first] =
              dis1[now1.second] + G1[now1.second][i].second;
          q1.push(make_pair(-dis1[G1[now1.second][i].first],
                            G1[now1.second][i].first));
        }
      }
    }
    writeln((quickPower(2, (min(dis1[n], dis1[n + n]) / (10000000))) - 1 +
             998244353 + (min(dis1[n], dis1[n + n]) % (10000000))) %
            998244353);
  }
}