#include <bits/stdc++.h>
using namespace std;
const long long MaxN = 200050;
const long long p = 998244353;
template <class t>
inline void read(t &s) {
  s = 0;
  register long long f = 1;
  register char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
  s *= f;
  return;
}
template <class t, class... A>
inline void read(t &x, A &...a) {
  read(x);
  read(a...);
}
template <class t>
inline void write(t x) {
  if (x < 0) putchar('-'), x = -x;
  long long buf[21], top = 0;
  while (x) buf[++top] = x % 10, x /= 10;
  if (!top) buf[++top] = 0;
  while (top) putchar(buf[top--] ^ '0');
  return;
}
inline void setIn(string s) {
  freopen(s.c_str(), "r", stdin);
  return;
}
inline void setOut(string s) {
  freopen(s.c_str(), "w", stdout);
  return;
}
inline void setIO(string s = "") {
  setIn(s + ".in");
  setOut(s + ".out");
  return;
}
template <class t>
inline bool checkmin(t &x, t y) {
  if (x > y) {
    x = y;
    return 1;
  }
  return 0;
}
template <class t>
inline bool checkmax(t &x, t y) {
  if (x < y) {
    x = y;
    return 1;
  }
  return 0;
}
inline long long lowbit(long long x) { return x & (-x); }
long long dis[MaxN], n, m;
bool vis[MaxN];
vector<long long> E[2][MaxN];
long long Dis[19][MaxN];
bool Vis[19][MaxN];
inline void spfa() {
  queue<pair<long long, long long> > Q;
  memset(Dis, 0x3f, sizeof Dis);
  Q.push(make_pair(0, 1));
  Dis[0][1] = 0;
  while (!Q.empty()) {
    register pair<long long, long long> u = Q.front();
    Q.pop();
    Vis[u.first][u.second] = false;
    for (auto v : E[u.first & 1][u.second])
      if (checkmin(Dis[u.first][v], Dis[u.first][u.second] + 1) &&
          !Vis[u.first][v])
        Q.push(make_pair(u.first, v)), Vis[u.first][v] = true;
    if (u.first < 18)
      for (auto v : E[!(u.first & 1)][u.second])
        if (checkmin(Dis[u.first + 1][v],
                     Dis[u.first][u.second] + (1 << u.first) + 1) &&
            !Vis[u.first + 1][v])
          Q.push(make_pair(u.first + 1, v)), Vis[u.first + 1][v] = true;
  }
  register long long ans = 0x3f3f3f3f3f3f3f3f;
  for (long long i = 0; i <= 18; ++i) checkmin(ans, Dis[i][n]);
  if (ans < 1e13) write(ans), puts(""), exit(0);
  return;
}
inline long long fpow(long long a, long long b) {
  register long long res = 1;
  for (; b; b >>= 1, a = a * a % p)
    if (b & 1) res = res * a % p;
  return res;
}
signed main(void) {
  read(n, m);
  register long long u, v;
  for (long long i = 1; i <= m; ++i)
    read(u, v), E[0][u].push_back(v), E[1][v].push_back(u);
  spfa();
  queue<long long> Q, q;
  memset(dis, 0x3f, sizeof dis);
  Q.push(1), q.push(1);
  dis[1] = 0;
  for (long long k = 0;; ++k) {
    while (!Q.empty()) {
      register long long u = Q.front();
      Q.pop();
      if (u == n) {
        write((fpow(2, k) - 1 + dis[u] + p) % p), puts("");
        return 0;
      }
      vis[u] = false;
      for (auto v : E[k & 1][u])
        if (checkmin(dis[v], dis[u] + 1) && !vis[v])
          Q.push(v), q.push(v), vis[v] = true;
    }
    while (!q.empty()) Q.push(q.front()), q.pop();
  }
  return 0;
}
