#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 998244353;
int f[maxn];
void solve() {
  int n, k;
  cin >> n >> k;
  set<int> s;
  for (int i = 0; i < min(n, k); i++) {
    int l, r;
    cin >> l >> r;
    s.insert(l);
    s.insert(r);
  }
  f[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (auto j : s)
      if (j < i) {
        f[i] = (f[i] + f[i - j] % mod) % mod;
      }
  }
  cout << f[n];
}
int main() {
  ios::sync_with_stdio(false);
  solve();
}
