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;
namespace fastIO {
bool IOerror = 0;
inline char nc() {
  static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;
  if (p1 == pend) {
    p1 = buf;
    pend = buf + fread(buf, 1, 100000, stdin);
    if (pend == p1) {
      IOerror = 1;
      return -1;
    }
  }
  return *p1++;
}
inline bool blank(char ch) {
  return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
inline long long read() {
  bool sign = 0;
  char ch = nc();
  long long x = 0;
  for (; blank(ch); ch = nc())
    ;
  if (IOerror) return 0;
  if (ch == '-') sign = 1, ch = nc();
  for (; ch >= '0' && ch <= '9'; ch = nc()) x = x * 10 + ch - '0';
  if (sign) x = -x;
  return x;
}
};  // namespace fastIO
using namespace fastIO;
struct node {
  int p, b;
  bool operator<(const node& v) const {
    if (p == v.p) return b < v.b;
    return p < v.p;
  }
  node operator+(const node& v) const { return node{p + v.p, b + v.b}; }
} dis[1000010];
struct nd {
  int v;
  node w;
  bool operator<(const nd& v) const { return v.w < w; }
};
int vis[1000010];
priority_queue<nd> q;
struct edge {
  int v;
  node w;
};
vector<edge> e[1000010];
int n, m;
void dij(int x) {
  for (int i = 1; i <= 2 * n; i++) dis[i] = node{2000000000, 0};
  dis[1] = node{0, 0};
  q.push(nd{1, dis[1]});
  while (!q.empty()) {
    nd now = q.top();
    q.pop();
    if (vis[now.v]) continue;
    vis[now.v] = 1;
    for (auto i : e[now.v]) {
      if (dis[now.v] + i.w < dis[i.v]) {
        dis[i.v] = dis[now.v] + i.w;
        q.push(nd{i.v, dis[i.v]});
      }
    }
  }
}
int po[10000010], dis2[10000010], vis2[10000010];
struct edge2 {
  int v, w;
};
vector<edge2> e2[5000010];
struct nde {
  int v, dis;
  bool operator<(const nde& vv) const { return dis > vv.dis; }
};
priority_queue<nde> q2;
void dij1(int x) {
  for (int i = 1; i <= 22 * n; i++) dis2[i] = 2100000000;
  dis2[1] = 0;
  q2.push((nde){1, 0});
  while (!q2.empty()) {
    nde now = q2.top();
    q2.pop();
    if (vis2[now.v]) continue;
    vis2[now.v] = 1;
    for (auto i : e2[now.v]) {
      if (dis2[i.v] > dis2[now.v] + i.w) {
        dis2[i.v] = dis2[now.v] + i.w;
        q2.push((nde){i.v, dis2[i.v]});
      }
    }
  }
}
signed main() {
  n = read(), m = read();
  po[0] = 1;
  for (int i = 1; i <= 2 * n; i++) po[i] = po[i - 1] * 2 % 998244353;
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    for (int j = 0; j < 22; j++) {
      if (j & 1)
        e2[j * n + y].push_back((edge2){j * n + x, 1});
      else
        e2[j * n + x].push_back((edge2){j * n + y, 1});
    }
    e[x].push_back(edge{y, node{0, 1}});
    e[y + n].push_back(edge{x + n, node{0, 1}});
  }
  for (int i = 1; i < 22; i++) {
    for (int j = 1; j <= n; j++)
      e2[(i - 1) * n + j].push_back((edge2){i * n + j, po[i - 1]});
  }
  dij1(1);
  int ans = 2100000000;
  for (int i = 0; i < 22; i++) ans = min(ans, dis2[i * n + n]);
  if (ans < 2000000000) return cout << ans % 998244353, 0;
  for (int i = 1; i <= n; i++) e[i].push_back(edge{i + n, node{1, 0}});
  for (int i = 1; i <= n; i++) e[i + n].push_back(edge{i, node{1, 0}});
  dij(1);
  if (dis[2 * n] < dis[n]) {
    cout << (po[dis[2 * n].p] - 1 + dis[2 * n].b) % 998244353;
  } else
    cout << (po[dis[n].p] - 1 + dis[n].b) % 998244353;
  return 0;
}