#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  while (cin >> n >> k) {
    vector<int> list;
    int dp[n + 1];
    for (int i = 0; i < k; i++) {
      int left, right;
      cin >> left >> right;
      for (int kk = left; kk <= right; kk++) {
        list.push_back(kk);
      }
    }
    sort(list.begin(), list.end());
    memset(dp, 0, sizeof(dp));
    dp[0] = 0;
    dp[1] = 1;
    for (int i = 1; i <= n; i++) {
      for (int r = 0; r < list.size(); r++) {
        if (i - list[r] >= 0) {
          dp[i] += dp[i - list[r]] % 998244353;
          dp[i] %= 998244353;
        }
      }
    }
    cout << dp[n] % 998244353 << endl;
  }
}
