#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<long long> v;
  vector<vector<int>> ch(k, vector<int>(2));
  for (int i = 0; i < (k); i++) {
    cin >> ch[i][0] >> ch[i][1];
  }
  for (int i = 1; i <= n; i++) {
    for (auto e : ch) {
      if (e[0] <= i && i <= e[1]) {
        v.push_back(i);
        break;
      }
    }
  }
  sort(v.begin(), v.end());
  vector<long long> dp(n, 0);
  dp[0] = 1;
  for (int i = 0; i <= n - 1; i++) {
    for (auto e : v) {
      if (i + e < n) {
        dp[i + e] += dp[i];
        dp[i + e] %= 998244353;
      }
    }
  }
  cout << dp[n - 1] << endl;
}
