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