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 long long MOD = 998244353;
template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}
long long inv[1000010 + 10], fac[1000010 + 10], ifac[1000010 + 10];
void setComb() {
  inv[0] = 1;
  inv[1] = 1;
  fac[1] = 1;
  ifac[1] = 1;
  fac[0] = 1;
  ifac[0] = 1;
  for (int i = 2; i < 1000010; i++) {
    inv[i] = (-MOD / i) * inv[MOD % i] % MOD;
    fac[i] = fac[i - 1] * i % MOD;
    ifac[i] = ifac[i - 1] * inv[i] % MOD;
    inv[i] = (inv[i] + MOD) % MOD;
    fac[i] = (fac[i] + MOD) % MOD;
    ifac[i] = (ifac[i] + MOD) % MOD;
  }
  return;
}
long long comb(long long n, long long k) {
  if (n < k || n < 0 || k < 0)
    return 0;
  else
    return ((fac[n] * ifac[k] % MOD * ifac[n - k] % MOD + MOD) % MOD);
}
long long hcomb(long long n, long long r) {
  if (n == 0 && r == 0)
    return 1;
  else if (n < 0 || r < 0)
    return 0;
  else
    return comb(n + r - 1, r);
}
long long binom(long long n, long long k) {
  if (n < k || n < 0 || k < 0) return 0;
  long long res = 1;
  for (long long i = 0; i < k; i++) res = res * (n - i) % MOD;
  res = res * ifac[k] % MOD;
  return res;
}
long long mod_pow(long long x, long long n) {
  x %= MOD;
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}
long long mod_inverse(long long x) { return mod_pow(x, MOD - 2); }
void add(long long &a, long long b) { a = (a + b) % MOD; }
void mul(long long &a, long long b) {
  a %= MOD;
  b %= MOD;
  a = a * b % MOD;
}
int N, M;
vector<vector<int>> g, rg;
pair<long long, long long> dp[200020][32];
const long long INF = 1e18;
void dijkstra() {
  priority_queue<
      pair<pair<long long, long long>, pair<long long, long long>>,
      vector<pair<pair<long long, long long>, pair<long long, long long>>>,
      greater<pair<pair<long long, long long>, pair<long long, long long>>>>
      PQ;
  PQ.push(make_pair(make_pair(0, 0), make_pair(0, 0)));
  while (!PQ.empty()) {
    auto f = PQ.top();
    PQ.pop();
    int now = f.second.first;
    long long num = f.second.second;
    long long ca = f.first.first;
    long long cb = f.first.second;
    if (dp[now][num] < f.first) continue;
    if (ca % 2) {
      for (auto nex : rg[now]) {
        if (dp[nex][num] > make_pair(ca, cb + 1)) {
          dp[nex][num].first = ca;
          dp[nex][num].second = cb + 1;
          PQ.push(make_pair(dp[nex][num], make_pair(nex, num)));
        }
      }
      for (auto nex : g[now]) {
        long long nn = num;
        if (nn == 30)
          nn = 31;
        else if (nn == 31)
          nn = 30;
        else
          nn++;
        if (dp[nex][nn] > make_pair(ca + 1, cb + 1)) {
          dp[nex][nn] = make_pair(ca + 1, cb + 1);
          PQ.push(make_pair(dp[nex][nn], make_pair(nex, nn)));
        }
      }
    } else {
      for (auto nex : g[now]) {
        if (dp[nex][num] > make_pair(ca, cb + 1)) {
          dp[nex][num].first = ca;
          dp[nex][num].second = cb + 1;
          PQ.push(make_pair(dp[nex][num], make_pair(nex, num)));
        }
      }
      for (auto nex : rg[now]) {
        long long nn = num;
        if (nn == 30)
          nn = 31;
        else if (nn == 31)
          nn = 30;
        else
          nn++;
        if (dp[nex][nn] > make_pair(ca + 1, cb + 1)) {
          dp[nex][nn] = make_pair(ca + 1, cb + 1);
          PQ.push(make_pair(dp[nex][nn], make_pair(nex, nn)));
        }
      }
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  setComb();
  cin >> N >> M;
  g.resize(N);
  rg.resize(N);
  for (int i = 0; i < (M); ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    rg[b].push_back(a);
  }
  for (int i = 0; i < (N); ++i)
    for (int j = 0; j < (32); ++j) dp[i][j] = make_pair(INF, INF);
  dijkstra();
  vector<long long> two(31, 0);
  two[0] = 1;
  for (int i = 0; i < (30); ++i) two[i + 1] = two[i] * 2;
  long long ans = INF;
  for (int j = 0; j < 30; j++) {
    long long val = dp[N - 1][j].first;
    if (val == INF) continue;
    long long c = dp[N - 1][j].second;
    chmin(ans, two[val] - 1 + c);
  }
  if (ans == INF) {
    if (dp[N - 1][30] <= dp[N - 1][31]) {
      ans = mod_pow(2ll, dp[N - 1][30].first);
      add(ans, MOD - 1);
      add(ans, dp[N - 1][30].second);
    } else {
      ans = mod_pow(2ll, dp[N - 1][31].first);
      add(ans, MOD - 1);
      add(ans, dp[N - 1][31].second);
    }
  }
  ans %= MOD;
  add(ans, MOD);
  cout << ans << endl;
  return 0;
}