#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    set<int> s;
    for (int i = 0; i < k; i++) {
      int x, y;
      cin >> x >> y;
      for (; x <= y; x++) s.insert(x);
    }
    int dp[n + 1];
    memset(dp, 0, sizeof(dp));
    dp[1] = 1;
    for (int i = 2; i <= n; i++) {
      for (auto ss : s)
        if (i - ss >= 0)
          dp[i] = (dp[i] + dp[i - ss]) % 998244353;
        else
          break;
    }
    cout << dp[n];
  }
  return 0;
}
