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;
using i128 = __int128_t;
using u128 = __uint128_t;
const long long MOD = 998244353;
const long double PI = 3.141592653589793238;
const long long pi = 31415926;
const long long inf = 1000000000000000000;
const long long small_inf = INT_MAX;
long long int modpow(long long int x, long long int n,
                     long long int mod = MOD) {
  long long int res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % mod;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}
long long int power(long long int x, long long int n) {
  long long int res = 1;
  while (n > 0) {
    if (n & 1) res = res * x;
    x = x * x;
    n >>= 1;
  }
  return res;
}
void init() {}
void solve() {
  int n, m;
  cin >> n >> m;
  std::vector<int> v[2][n + 1];
  vector<pair<int, pair<long long int, long long int>>> v1[2 * n + 1];
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    v[0][x].push_back(y);
    v[1][y].push_back(x);
    v1[x].push_back(make_pair(y, make_pair(0, 1)));
    v1[n + y].push_back(make_pair(n + x, make_pair(0, 1)));
  }
  for (int i = 1; i <= n; i++) {
    v1[i].push_back(make_pair(n + i, make_pair(1, 0)));
    v1[n + i].push_back(make_pair(i, make_pair(1, 0)));
  }
  std::vector<std::vector<long long>> dist(
      2, std::vector<long long int>(n + 1, inf));
  dist[0][1] = 0;
  for (int fu = 0; fu <= 30; fu++) {
    int f = fu % 2;
    set<pair<long long int, int>> s;
    for (int i = 1; i <= n; i++) {
      if (dist[f][i] != inf) s.insert(make_pair(dist[f][i], i));
    }
    std::vector<int> vis(n + 1, 0);
    while (!s.empty()) {
      pair<long long int, int> p = *s.begin();
      s.erase(s.begin());
      int x = p.second;
      long long int d = p.first;
      if (vis[x]) continue;
      vis[x] = 1;
      for (auto y : v[f][x]) {
        if (!vis[y] && d + 1 < dist[f][y]) {
          dist[f][y] = d + 1;
          s.insert(make_pair(d + 1, y));
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      dist[f ^ 1][i] = min(dist[f ^ 1][i], dist[f][i] + power(2, fu));
    }
  }
  if (dist[0][n] != inf || dist[1][n] != inf) {
    cout << min(dist[0][n], dist[1][n]) % MOD << endl;
    return;
  }
  vector<pair<long long int, long long int>> dis(2 * n + 1,
                                                 make_pair(inf, inf));
  {
    set<pair<pair<long long int, long long int>, int>> s;
    dis[1] = make_pair(0, 0);
    s.insert(make_pair(dis[1], 1));
    std::vector<int> vis(2 * n + 1, 0);
    while (!s.empty()) {
      pair<pair<long long int, long long int>, int> p = *s.begin();
      s.erase(s.begin());
      if (vis[p.second]) continue;
      vis[p.second] = 1;
      int x = p.second;
      long long int num = p.first.first, d = p.first.second;
      for (auto y : v1[x]) {
        if (vis[y.first] || make_pair(num + y.second.first,
                                      d + y.second.second) >= dis[y.first])
          continue;
        dis[y.first] = make_pair(num + y.second.first, d + y.second.second);
        s.insert(make_pair(dis[y.first], y.first));
      }
    }
  }
  pair<long long int, long long int> p;
  if (dis[n].first < dis[2 * n].first)
    p = dis[n];
  else if (dis[2 * n].first < dis[n].first)
    p = dis[2 * n];
  else if (dis[2 * n].second < dis[n].second)
    p = dis[2 * n];
  else
    p = dis[2 * n + 1];
  long long int ans = p.second % MOD;
  for (int i = 0; i <= p.first - 1; i++) {
    ans += modpow(2, i);
    ans %= MOD;
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int t23 = 1, tt23 = 1;
  init();
  while (tt23 <= t23) {
    solve();
    tt23++;
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
}