#include <bits/stdc++.h>
using namespace std;
int main() {
  const long long int mod = 998244353;
  int n, k, l, r;
  cin >> n >> k;
  vector<int> s;
  for (int i = 0; i < (k); ++i) {
    cin >> l >> r;
    s.push_back(l);
    if (l != r) s.push_back(r);
  }
  long long int dp[n];
  dp[0] = 1;
  for (int i = 1; i < n; ++i) {
    dp[i] = 0;
    for (int a : s) {
      if (i - a >= 0) {
        dp[i] += dp[i - a];
        dp[i] %= mod;
      }
    }
  }
  cout << dp[n - 1] << endl;
}
