#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  {
    long long int n, k;
    cin >> n >> k;
    long long int x, y;
    set<long long int> s;
    while (k--) {
      cin >> x >> y;
      for (int i = x; i <= y; i++) s.insert(i);
    }
    long long int dp[n + 1];
    memset(dp, 0, sizeof(dp));
    dp[1] = 1;
    long long int M = 998244353;
    for (int i = 1; i <= n; i++) {
      if (!dp[i]) continue;
      for (auto it : s) {
        if (it + i > n) break;
        dp[it + i] += dp[i] % M;
      }
      dp[i] %= M;
    }
    cout << dp[n] % M;
  }
}
